Unrolled loops

JavaScript performance comparison

Test case created by Thomas Fuchs

Info

It seems the latest and greatest JavaScript engines have catched up and loop unrolling is not as great a speedup as it once was. Still, both unrolled loop variants are 10% to 25% faster than the for loop on both Safari 5 and Chrome 5.

Preparation code

<script>
  var a = 0;
</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
For loop
for (var i = 0; i < 100; i++) a++;
pending…
Unrolled loop
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
a++;
pending…
Unrolled loop (1 statement)
a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++, a++;
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