Prefix or Postfix increment?

JavaScript performance comparison

Revision 10 of this test case created

Info

So with recent JS runtimes, does using the prefix increment/decrement operators squeeze the usual performance droplet from loop index maintenance?

Preparation code

<script>
  var data = new Array(500 * 1000);
  var index = data.length - 1;
  while (index--) data[index] = index;
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Prefix
var x;
for (var index = 0, len = data.length; index < len; ++index) {
  x = index;
}
pending…
Suffix
var x;
for (var index = 0, len = data.length; index < len; index++) {
  x = index;
}
pending…
Crockford
var x;
for (var index = 0, len = data.length; index < len; index += 1) {
  x = index;
}
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