Normal loops vs bundle loops vs reverse loops

Benchmark created by EtnasSoft on


Preparation HTML

<script>
  var x = 0,
      a = [1,1,2,3,5,8,13,21,34,55];
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Normal Loop
for (var i = 0, l = a.length; i < l; i++){
  x += a[i];
}; // cached length
 
ready
Bundled Loop
for (var i = -1, l = a.length; ++i < l;){
  x += a[i];
}; // bundled condition (increment+test)

 
ready
Reversed Loop
for (var i = a.length; i--;){
  x += a[i];
}; // reverse loop 
ready

Revisions

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

  • Revision 1: published by EtnasSoft on