i++ vs ++i
JavaScript performance comparison
Info
The hello world books of programming always start you off with i++, however did you know that i++ comes with a bit of overhead? that's because before you can increment i under the hood a new copy of i must be created. Using ++i you don't need that extra copy. i++ will return the current value before incrementing i. ++i returns the incremented version i. This test is to demonstrate that it's faster to use ++i. Get ready get set update your code!
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
100000 iterations of ++i |
|
pending… |
100000 iterations of i++ |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 2: published
- Revision 3: published
1 comment
So, there seems to be no difference at all as browsers have adapted to that behavior...