- microtime: documentation ( source)
<?php
class SomeClass
{
static function doTest($var) {return $var;}
}
class SomeObj
{
function doTest($var) {return $var;}
static function doTest2($var) {return $var;}
}
//bench static call
$starttime = microtime(true);
for ($i = 0; $i< 100000; $i++)
SomeClass::doTest($i);
echo "Static call time: " , (microtime(true)-$starttime) , " ms
";
//bench object method
$starttime = microtime(true);
$obj = new SomeObj();
for ($i = 0; $i< 100000; $i++)
$obj->doTest($i);
echo "Object method call time: " , (microtime(true)-$starttime) , " ms
";
//bench static call
$starttime = microtime(true);
for ($i = 0; $i< 100000; $i++)
SomeObj::doTest2($i);
echo "Static call (when the static is in the same class of object method) time: " , (microtime(true)-$starttime) , " ms
";