[TYPO3-core] RFC #0011512: replace while(list()...) by foreach in the TYPO3 core part 1

Ernesto Baschny [cron IT] ernst at cron-it.de
Thu Jul 16 11:21:56 CEST 2009


Benjamin Mack schrieb:

> http://www.phpbench.com/
> 
> see Read Loop:foreach() vs. for() vs. while(list() = each())
> 
> Citing:
> "In all cases I've found that the foreach loop is substantially faster
> than both the while() and for() loop procedures. One thing to note is
> that when using an entire loop from the start it's extremely good to use
> the reset() function in all examples"

That is easy to "say" without a proof. I cannot confirm this in my tests.

My tests used the same array as in the mentioned link ("Hash array with
100 elements, 24byte key and 10k data per entry"). And I ran 500.000
times the "foreach($aHash as $val);" loop with and without a reset() before.

The results:

with reset() = 100.00%
without reset() = 88.38%

The "reset()" itself needs more time than it brings something
beneficial. And also looks ugly in the code.

Cheers,
Ernesto


More information about the TYPO3-team-core mailing list