Toomas Römer

PHP and microbenchmarks

August 1st, 2008 | by Toomas Römer |

Microbenchmarks always have to be taken with a grain of salt. I do know that but I happened to stumble upon a PHP optimization tip Avoid overusing function calls.

The test is fairly simple. 4 million iterations of $j = 1 and 4 million iterations of some_func(), a function wrapping the same $j = 1.

The results? Function calls are so expensive that inlined version takes 2 seconds to execute and invoking the function takes 16. 8 time difference, whoah!

The test environment: PHP 5.2.6-2+b1 with Suhosin-Patch 0.9.6.2 (cli) (built: Jul 22 2008 21:03:43) running on a P4@3ghz

  • Toomas Römer
    Well, the eAccelerator does not support cli/cgi, Zend optimizer on the other hand advertises itself as a runtime to run encoded PHP scripts. So seems too much hassle and possibly no gain.

    I did run the tests with the latest Quercus engine. The average ratio was 3.22. Beats the native PHP :)

    You can give it a try. The archive can be found from here http://ngra.de/files/benchmark.zip and to execute just: java -Xbootclasspath/a:quercus.jar:resin-util.jar:script-10.jar -jar benchmark.jar

    Let me know what do you get.
  • Jevgeni Kabanov
    What about if you use some kind of optimizing compiler? I though Zend engine was something like that... Also, did you try Quercus?
blog comments powered by Disqus