Created
March 4, 2010 23:00
-
-
Save predominant/322223 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 A { | |
private static $__value = 'Foo'; | |
public function getValue() { | |
return self::$__value; | |
} | |
} | |
class B { | |
private static $__value = 'Foo'; | |
public function getValue() { | |
return static::$__value; | |
} | |
} | |
$iterations = 5000000; | |
$results = array(); | |
$a = new A(); | |
for ($loop = 0; $loop < 5; $loop++) { | |
$start = microtime(true); | |
for ($i = 0; $i < $iterations; $i++) { | |
$a->getValue(); | |
} | |
$elapsed = microtime(true) - $start; | |
$results[] = $elapsed; | |
} | |
unset($a); | |
$average = array_sum($results) / count($results); | |
echo "self:: => $average\n"; | |
$results = array(); | |
$b = new B(); | |
for ($loop = 0; $loop < 5; $loop++) { | |
$start = microtime(true); | |
for ($i = 0; $i < $iterations; $i++) { | |
$b->getValue(); | |
} | |
$elapsed = microtime(true) - $start; | |
$results[] = $elapsed; | |
} | |
unset($b); | |
$average = array_sum($results) / count($results); | |
echo "static:: => $average\n"; | |
// Results (PHP 5.3.0 cli) | |
// self:: => 2.2726522445679 | |
// static:: => 2.2912198543549 | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment