Re: Performance: While or For loop

From: Date: Sat, 24 Mar 2007 00:47:29 +0000
Subject: Re: Performance: While or For loop
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-251239@lists.php.net to get a copy of this message
On Thu, March 22, 2007 5:14 pm, Tijnema ! wrote: > On 3/22/07, Jon Anderson <janderson@gamingsolutions.ca> wrote: >> Your test isn't exactly fair. The for loop has no statements in it, >> and >> the while loop has one. Your tests show while as approx 7% faster, >> while >> a modified test shows an approximate 30% speed improvement: >> >> Do this: >> >> for ($i=0;$i<10000000;$i++) {} >> >> v.s.: >> >> $i = 0; >> while ($i++ < 10000000) {} >> >> The above while loop is 30% faster than the for. A little teaking on >> the >> for loop, it's faster still: Folks: How often do you use a loop of any kind in PHP with enough iterations that this is even significant? Write the code that makes sense. Optimize the biggest bottleneck until performance is acceptable. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So?

« previous php.general (#251239) next »