On Mar 10, 2:18 pm, Chris <chrisageo...@gmail.com> wrote: > Also interesting:http://jsperf.com/if-with-i/5 > > Accessing it without "caching" the object from the array in a variable is > 94% slower.
In what browser? In my IE 6 the one that doesn't store the value is faster (for your tests). Anyway, your tests are faulty - the while with assignment in the condition is 500 times faster in Firefox and a staggering 5,500 times faster in IE. That should give you a hint something is wrong (there is some optimisation occuring that can't be sustained). I created some tests with random values in an array to prevent that type of optimisation: <URL: http://jsperf.com/loops-test-2011-03-10/3 > In IE 6, doing assignment in the condition is about 10% faster than not, but in Firefox it is about 5% slower. So what you win on the roundabouts you lose on the swings. And the speed of for, while and do are all about the same, so no point in picking one over the other for speed. In any case, even my old IE is doing 3,500,000 iterations per second (700 ops x 5,000 loops each) and Firefox about 20,000,000 (4,000 x 5,000) so loop speed is not really an issue. -- Rob -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/jsmentors@jsmentors.com/ To search via a non-Google archive, visit here: http://www.mail-archive.com/jsmentors@googlegroups.com/ To unsubscribe from this group, send email to jsmentors+unsubscr...@googlegroups.com