i++ vs ++i vs i+=1

JavaScript performance comparison

Revision 5 of this test case created by Joshua Scott

Info

Test to see which is fastest, i++, ++i, or i+=1 in a for loop

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
100000 iterations of ++i
for (var x = 0, i = 0; i < 100000; ++i) { x = i; }
pending…
100000 iterations of i++
for (var x = 0, i = 0; i < 100000; i++) { x = i; }
pending…
100000 iterations of i+=1
for (var x = 0, i = 0; i < 100000; i+=1) { x = 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:

0 comments

Add a comment