Suffolk County Math Tournament in 2 days
Fri January 9, 2009
Fri January 9, 2009
PUMaC in 24 days
Sat January 31, 2009
Sat January 31, 2009
AMC 12A in 34 days
Tue February 10, 2009
Tue February 10, 2009
HMMT in 45 days
Sat February 21, 2009
Sat February 21, 2009
World Math Day in 56 days
Wed March 4, 2009
Wed March 4, 2009
AIME I in 82 days
Mon March 30, 2009
Mon March 30, 2009
PLUS! magazine deadline in 83 days
Tue March 31, 2009
Tue March 31, 2009
USAMO in 111 days
Tue April 28, 2009
Tue April 28, 2009
ARML in 142 days
Fri May 29, 2009
Fri May 29, 2009
21st Birthday in 613 days
Sun September 12, 2010
Sun September 12, 2010
Turning 40 in 7553 days
Wed September 12, 2029
Wed September 12, 2029

















What about foreach?
Why wouldn't you write
for any array? It should work on all of them, and is IMO a little easier to understand. Is it even worse than for()?
But, if for is actually slower than while, it means php must be even more broken than I thought; there should be no reason for that. Any worthwhile compiler (PHP is compiled, just on the fly, how I understand it) should cache the result of length($array), and memory usage should be the same; all three loop types in any sane environment would be exactly the same.
Foreach is a very slow loop
Foreach is a very slow loop and I only see associative arrays when I'm working with db queries, so I don't think there is point use Foreach for everything. Also, some loops you want to do something with the previous or next element in the array.
Usually, people make associative arrays as objects.
I don't know about the length($array) should be cached. the length of the array can change.
You might be right, I'm not an expert in the PHP interpreter.
Thanks for that, most of
Thanks for that, most of those things I didn't know. I remember reading about the $i++ versus ++$i, although I had never applied it (unless I explicitly needed ++$i). Besides that, I have now started applying these rules to my code :)
Well, usually, if you apply
Well, usually, if you apply all these techniques, your application might get 10% gain in speed.
Sometimes, finding the better way of doing something gives me 650 times faster application. For example the prime spiral one
I was thinking over this
I was thinking over this post last night and was wondering which of the following is fastest for looping over iterators...
They are all essentially the same thing because all five functions are implicitly/explicitly called.
I'm going to test that
I'm going to test that pretty soon...
Things becomes tricky when objects are evolved.
optimized while loop not correct?
Hi, i think the optimized while loop is not working as you expect.
you never come to array[0] because the while condition will not evaluate to true if $i == 0.
it should work if you use while (-1 != $i) { ... }
question would be if it is then still faster than the other ways.
ciao,
tauven
I updated it, thx! $count =
I updated it, thx!
it is still as fast. it does count($array) amount of loop now.
Post new comment