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";
< /code>
Выходы: < /p>
Static Time: 0.640204906464 ms
Object Time: 0.48961687088 ms
Function Time: 0.438289880753 ms
< /code>
Я знаю, что фактическое время по-прежнему незначительно, если я на самом деле не называю что-то 1 миллион раз, но факт, что оно там. < /p>
Кто-нибудь захочет попытаться объяснить, что происходит за кулисами?
< /p>
>
Подробнее здесь: https://stackoverflow.com/questions/147 ... -functions