News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Joakim Nygard's Blog:
Optimizing PHP Through Habits
April 25, 2007 @ 10:39:00

Spurred on by some previous benchmarks [pdf] from Ilia Alshanetsky, Joakim Nygard decided to run some his own benchmarks on the same sort of functionality.

There are numerous discussions in the blogosphere about whether to use echo versus print, if for() is faster than while(), etc. and though the gains are usually very small, I decided to add my thoughts to the debate. I found an article on optimization through coding habits in Ilia Alshanetsky's zend performance slides.

According to his results:

  • Calling require_once() 10000 times in a for() loop with an empty file is 4x faster.
  • With a simply autoload requiring a class and 10000 loops of new Foo() versus require_once('foo.php'); new Foo() shows that __autoload() is ~3.7 times faster.
  • If a class method can be static, declare it static. Speed improvement is by a factor of 4.
  • Avoid function calls within for() loop control blocks
  • Always, always quote array keys.
  • Get rid of 'harmless' error messages - they take time to generate and output.

I am not out to prove Ilia wrong - he knows PHP better than most - and for all I know, they could have optimized those very functions in PHP 5.2. [...] It would appear that there are improvements, albeit small, to achieve from minimal effort. Plus I was surprised by the discrepancies I found compared to Ilia's recommendations.
0 comments voice your opinion now!
optimize coding habit benchmark requireonce autoload loop optimize coding habit benchmark requireonce autoload loop


blog comments powered by Disqus

Similar Posts

Sander van de Graaf's Blog: Optimizing your (ZF) web application

WebDevLogs.com: BREAK the FOR VS WHILE loop war

Eran Galperin's Blog: Database Optimization Techniques You Can Actually Use

Start up web 2.0 Blog: CakePHP & CodeIgniter Benchmark

Liip Blog: HHVM with Symfony 2 looks amazing


Community Events





Don't see your event here?
Let us know!


series interview symfony install api list framework language podcast deployment release tips opinion introduction bugfix community package library laravel voicesoftheelephpant

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework