Re: Performance: While or For loop

From: Date: Thu, 22 Mar 2007 21:39:58 +0000
Subject: Re: Performance: While or For loop
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-251133@lists.php.net to get a copy of this message
On 3/22/07, Jake McHenry <linux@nittanytravel.com> wrote:
does this help? http://www.php.lt/benchmark/phpbench.php Jake
Well, there wasn't a test between For and While, so i did it myself, and i'm quite confused about the result. I let PHP count from 0 to 100000000 on my 1ghz AMD Athlon. While did it in a average time of 55 seconds. For did it in a average time of 59 seconds. It's not a big difference, if you see what number it needs to go to, but there is a difference. code used: <?php set_time_limit(100000); echo date("H:i:s"); for($i = 0; $i < 100000000;$i++) { } echo date("H:i:s"); $x = 0; while($x < 100000000) { $x++; } echo date("H:i:s"); ?> So, use while loops instead of for loops ;) Tijnema ps. I also did the while loop before the for loop, doesn't matter.
-----Original Message----- From: Tijnema ! [mailto:tijnema@gmail.com] Sent: Thursday, March 22, 2007 4:38 PM To: PHP Subject: [PHP] Performance: While or For loop Hi, Does somebody has benchmarks of what is faster, while or for loop? Thanks, Tijnema -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.17/730 - Release Date: 3/22/2007 7:44 AM -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.17/730 - Release Date: 3/22/2007 7:44 AM -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#251133) next »