Skip to content

Instantly share code, notes, and snippets.

@funkatron
Created February 8, 2014 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funkatron/8876477 to your computer and use it in GitHub Desktop.
Save funkatron/8876477 to your computer and use it in GitHub Desktop.
<?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