++iare speed-equivalent, and are mostly a style issue for loop counters.
++iare about 1.5x faster than
i = i + 1or
i += 1
- JIT makes the differences between all forms vanish
- Do remember to use
varin loop counters (and in general). With out it, loops can be 4x slower.
i += 1 are probably a bugfix away from being speed-equivalent ( via bytecode optimization).
i++are equivalent, and are mostly a stylistic issue.
i = i + 1are equivalent, but 1.6x slower than
- In this trivial case, the JIT makes the code 30-60x faster.
What happens when you forget to put in the
Holy smokes. It makes the code 4x slower. Oddly JIT'ed version actually goes faster, but it's "only" 140x faster than the interpreted version. As for the last entry, I have no idea why another variable added to the script makes it go 10% slower
There you have it. Don't obsess over this too much. It's more interesting than useful.
Comment 2009-05-04 by None