Skip to content

Instantly share code, notes, and snippets.

@Rican7
Created October 17, 2013 21:58
Show Gist options
  • Save Rican7/7032967 to your computer and use it in GitHub Desktop.
Save Rican7/7032967 to your computer and use it in GitHub Desktop.
<?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