In PHP, (unlike what I originally thought) there is an overhead of calling static methods vs simple functions.
On a very simple bench, the overhead is over 30% of the calling time (the method just returns the parameter):
// bench static method
$starttime = microtime(true);
for ($i = 0; $i< 10*1000*1000; $i++)
SomeClass::doTest($i);
echo "Static Time: " , (microtime(true)-$starttime) , " ms\n";
// bench object method
$starttime = microtime(true);
for ($i = 0; $i< 10*1000*1000; $i++)
$someObj->doTest($i);
echo "Object Time: " , (microtime(true)-$starttime) , " ms\n";
// bench function
$starttime = microtime(true);
for ($i = 0; $i< 10*1000*1000; $i++)
something_doTest($i);
echo "Function Time: " , (microtime(true)-$starttime) , " ms\n";
outputs:
Static Time: 0.640204906464 ms
Object Time: 0.48961687088 ms
Function Time: 0.438289880753 ms
I know the actual time is still negligible unless I am actually calling something 1 million times, but the fact is that its there.
Will anyone care to try and explain what is happening behind the scenes?
update:
- added object method bench