I whipped up a quick JSLitmus test to try out a handful of empty loops
(using i++, ++i, i+=1, and a while loop:
View the [very short] source of the page to see the actual test code. When
running the test for yourself, be sure to uncheck the "normalize" box. Also,
you'll probably want to run each test a few times to make sure you're
getting consistent results (CPU load elsewhere in the OS can skew resutls).
For more on JSLitmus, read http://www.broofa.com/Tools/JSLitmus )
Here are the results I got on my MacBook (sorry, don't have IE results
Executive summary: On the above browsers, performance does vary. i++ or ++i
are the best all-round performers, while the while() loop is generally not
as good. However on all of these systems ('cept Opera), looping code runs
so fast that performance is negligable compared to whatever code you put
inside the loop. I.e. it's unlikely to matter in all but the most trivial
On Wed, Dec 16, 2009 at 2:28 AM, Yaffle <vic99...@yandex.ru> wrote:
> ++i; is a little more efficient in C language,
> On Dec 16, 3:21 pm, RQuadling <rquadl...@googlemail.com> wrote:
> > Hi.
> > Is there any consensus on which is more efficient in a for() loop?
> > I was taught that for ++i being the most efficient.
> > I've created 2 patches (++ and a +1) in case anyone is interested.
> > http://pastie.org/private/3rgonpsn90yjd17q9zwa
> > andhttp://pastie.org/private/qufy3rwmaevxc1sysvq
> > From what I've read, this could be a little pointless, but I'm not the
> > expert in this area.
> > Regards,
> > Richard.
> You received this message because you are subscribed to the Google Groups
> "Prototype: Core" group.
> To post to this group, send email to email@example.com
> To unsubscribe from this group, send email to
> For more options, visit this group at
You received this message because you are subscribed to the Google Groups
"Prototype: Core" group.
To post to this group, send email to firstname.lastname@example.org
To unsubscribe from this group, send email to
For more options, visit this group at