Re: Performance: While or For loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 3/27/07, Travis Doherty <travis@xxxxxxxxxxxxx> wrote:
Jake Gardner wrote:

> He said if you run the /script/ itself 1000 times, not a loop with 1000
> iterations. This is quite possible; I am fairly certain there are
> websites
> out there that get accessed well over 1000 times a minute, yes?
>
> So every minute, that website is saving a total of 2.6 seconds to do...
> whatever it is websites do in their free time.
>
> In reality, scripts rarely get executed once and then are deleted;
> they are
> used repetitively, and the more a script is used, the more significant
> the
> gain. Claiming to look practically on a small gain /within one
> execution of
> a script/ is impractical in itself.

I still wouldn't go around telling people to re-write all of their code
to use for loops instead of while loops (or whatever was faster for
whatever architecture.)

While loops came out faster :)

Keep in mind that .000xx seconds in performance improvement certainly
does make a difference on a site that is accessed millions of times a
day, however, one bug caused by writing code that reads poorly instead
of writing clean code can cost a *lot* more in the end.

- Use what reads easier when deciding if a for/while loop is best.
- Profile your code and find the right places to optimize.

Optimizing code that takes .0001 seconds to run down to .00001 seconds
is great, 10x improvement!  Who cares. Find the chunk that takes 0.5
seconds to run and optimize that to 0.05 seconds. 10x improvement still,
except that this time it actually makes a practical difference.

Travis Doherty

I'm not telling people to rewrite the code, but if you need to choose,
and both are good for the job, choose while :)

Tijnema


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux