Created
October 17, 2013 21:58
-
-
Save Rican7/7032967 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Dog { | |
public function paramSmart($val = null) { | |
if (null !== $val) { | |
return $this->paramSmart = $val; | |
} | |
return $this->paramSmart; | |
} | |
} | |
class Cooper extends Dog { | |
public function paramSmaht($val = null) { | |
if (func_num_args() > 0) { | |
return $this->paramSmart = $val; | |
} | |
return $this->paramSmart; | |
} | |
} | |
function bench($test_obj, $iters = 1000) { | |
echo PHP_EOL; | |
$first_obj = clone $test_obj; | |
$second_obj = clone $test_obj; | |
$init = microtime(true); | |
for ($i = 0; $i < $iters; $i++) { | |
$first_obj->paramSmart('testing'); | |
$first_obj->paramSmart(); | |
} | |
printf('paramSmart time taken: %f'.PHP_EOL, (microtime(true) - $init)); | |
$init = microtime(true); | |
for ($i = 0; $i < $iters; $i++) { | |
$second_obj->paramSmaht('testing'); | |
$second_obj->paramSmaht(); | |
} | |
printf('paramSmaht time taken: %f'.PHP_EOL, (microtime(true) - $init)); | |
echo PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment