i++ vs ++i

JavaScript performance comparison

Test case created by MONTILLET Xavier

Info

Fastest increment.

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
i++ | Post-increment
var i = 0,
    pre = 0,
    post = 0;
while (i < 999) {
 pre += i;
 i++;
 post += i;
}
if (pre !== 498501 || post !== 499500) {
 throw new Error("Bad result!");
}
pending…
++i | Pre-increment
var i = 0,
    pre = 0,
    post = 0;
while (i < 999) {
 pre += i;
 ++i;
 post += i;
}
if (pre !== 498501 || post !== 499500) {
 throw new Error("Bad result!");
}
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment