On Mon, 2003-08-11 at 13:29, Chris W. Parker wrote:
>
> * while loop
>
> $ctr = 0;
> $val = 0;
> while($ctr<100000)
> {
> $val++;
> $ctr++;
> }
>
> ** for loop
>
> $val = 0;
> for($ctr=0;$ctr<100000;$ctr++)
> {
> $val++;
> }
>
I get the following results (very consistently +/- .1) which agrees with
your results and also shows an improvement over your own optimization.
for( $i = 0; $i < 10000000; $i++ ){}
> time php foo.php
Content-type: text/html
X-Powered-By: PHP/4.3.2
4.42user 0.03system 0:04.60elapsed 96%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (528major+216minor)pagefaults 0swaps
-----------------------------------------------------------
$i = 0;
while( $i < 10000000 ){ $i++; }
> time php fee.php
Content-type: text/html
X-Powered-By: PHP/4.3.2
4.22user 0.01system 0:04.43elapsed 95%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (527major+216minor)pagefaults 0swaps
-----------------------------------------------------------
$i = 0;
while( $i++ < 10000000 ){}
> time php foo.php
Content-type: text/html
X-Powered-By: PHP/4.3.2
2.97user 0.00system 0:03.09elapsed 96%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (526major+216minor)pagefaults 0swaps
-----------------------------------------------------------
Notice the large difference when the incrementation occurs within the
while check itself.
Cheers,
Rob.
--
.---------------------------------------------.
| Worlds of Carnage - http://www.wocmud.org |
:---------------------------------------------:
| Come visit a world of myth and legend where |
| fantastical creatures come to life and the |
| stuff of nightmares grasp for your soul. |
`---------------------------------------------'
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php