News Feed
Sections




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

Gonzalo Ayuso's Blog:
Checking the performance reading arrays with PHP
August 16, 2011 @ 11:46:07

While admitting that micro-optimizations aren't usually worth the time that's taken to worry about them, Gonzalo Ayuso has thrown together some array read benchmarks to show the difference, if any, in where array values are fetched.

Normally our code is coded once and executed thousands of times, and we must keep in mind that CPU time many times means money. We need to balance it (as always). But, WTH. I like micro-optimizations, and here comes another one: Checking the access to arrays with PHP.

He sets up three different options and tests the memory consumption and run time for each:

  • Referencing a value from a large array outside a for loop
  • Referencing a value from a large array inside a for loop
  • Echoing out the value from a large array inside a for loop

Not surprisingly, all three approaches yield just about the same results. It probably has more to do with the size of the large array than how it's accessed. The fetch outside the for loop did come in slightly under the others, but not enough to worry about it.

0 comments voice your opinion now!
performance array microoptimization read memory runtime


blog comments powered by Disqus

Similar Posts

Stijn Leenknegt's Blog: [PHP6] function-return-array idea!

Stanislav Malyshev's Blog: Ruby-like iterators in PHP

Lukas Smith's Blog: Remember: be nice to byte code caches

Felix Geisendorfer's Blog: PHP 5.2.1 was a evil release - check your server

Stubbles Blog: Two New PHP6 Wishlist Items


Community Events





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


list tips framework series deployment introduction release symfony developer api laravel interview voicesoftheelephpant zendserver podcast language community library bugfix conference

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