Created
February 8, 2014 03:57
-
-
Save funkatron/8876477 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 | |
// Anonymous function (Closure object) | |
$foo = function () { | |
echo ''; | |
}; | |
// procedural function | |
function foo() | |
{ | |
echo ''; | |
} | |
// Class with static method | |
class Foostat | |
{ | |
public static function foo() | |
{ | |
echo ''; | |
} | |
} | |
$iterations = 1000000; | |
ob_start(); | |
$t = microtime(true); | |
$i = 0; | |
while ($i < $iterations) { | |
$foo(); | |
++$i; | |
} | |
$tmp = microtime(true) - $t; | |
ob_end_clean(); | |
echo "\$foo() : {$tmp}\n"; | |
ob_start(); | |
$t = microtime(true); | |
$i = 0; | |
while ($i < $iterations) { | |
foo(); | |
++$i; | |
} | |
$tmp = microtime(true) - $t; | |
ob_end_clean(); | |
echo "foo() : {$tmp}\n"; | |
ob_start(); | |
$t = microtime(true); | |
$i = 0; | |
while ($i < $iterations) { | |
Foostat::foo(); | |
++$i; | |
} | |
$tmp = microtime(true) - $t; | |
ob_end_clean(); | |
echo "Foostat::foo() : {$tmp}\n"; | |
ob_start(); | |
$t = microtime(true); | |
$i = 0; | |
while ($i < $iterations) { | |
call_user_func('foo'); | |
++$i; | |
} | |
$tmp = microtime(true) - $t; | |
ob_end_clean(); | |
echo "call_user_func('foo') : {$tmp}\n"; | |
ob_start(); | |
$t = microtime(true); | |
$i = 0; | |
while ($i < $iterations) { | |
call_user_func('Foostat::foo'); | |
++$i; | |
} | |
$tmp = microtime(true) - $t; | |
ob_end_clean(); | |
echo "call_user_func('Foostat::foo') : {$tmp}\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment