i++ vs ++i

Benchmark created by MONTILLET Xavier on


Test runner

Ready to run.

Testing in
TestOps/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!");
}
ready
++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!");
}
ready

Revisions

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

  • Revision 1: published by MONTILLET Xavier on