[TYPO3-dev] FYI: comparing execution speed of some php functions
Ries van Twisk
typo3 at rvt.dds.nl
Sun Jun 28 17:09:42 CEST 2009
On Jun 28, 2009, at 9:59 AM, Steffen Kamper wrote:
> Hi Niels,
>
> no - it'S a different issue.
>
> I tried with adding this to Rupi's script:
>
> $GLOBALS['myClass'] = new mytestclass();
> $S = microtime(TRUE);
> for ($i = 0; $i < $num; ++ $i) {
> $GLOBALS['myClass']->testfunc(1);
> }
> $E = microtime(TRUE) - $S;
> echo "global object call took \t" . number_format(floatval($E * 1000),
> 5) . " ms\n";
>
> these are the results:
> calling methods in classes:
> ---------------------------------------------
> object call took 347.18299 ms
> derived object call took 359.87806 ms
> static call took 523.85497 ms
> global object call took 375.33998 ms
>
> (oh god, my numbers are 8 times slower than Rupis, what's wrong with
> my
> machine?)
>
> but, after isolating the object calls (removing all other tests) i got
> incredible different results:
>
> object call took 0.02289 ms
> derived object call took 0.01001 ms
> static call took 0.00811 ms
> global object call took 0.00811 ms
>
> and this is completely the other way showing that static class calls
> are
> faster than object calls.
>
> As this example shows, don't trust results before you did an isolate
> test. The performance of php completely change after filling memory
> etc.
>
> vg Steffen
I believe that static methods will be compiled in-line if possible,
however I think this is still up to the compiler to make a final
decision.
Creating a static method and just return 1 is not really a good test
without knowing what decisions a compiler can take to compile or
not compile the method in-line or not, this was shown in the PDF
here : http://ilia.ws/files/phptek2007_performance.pdf
I can imagine that if a function is called many times from different
locations
and the static method is large, the compiler might not decide to compile
the final code in-line and decide to reduce file size instead.
So what steffen points out is right, be careful with such simple tests
and don't draw conclusions without testing it in a real world scenarios.
Ries
More information about the TYPO3-dev
mailing list