With lint compliance (v63)

Revision 63 of this benchmark created by Developingo on


Setup

// Populate the base array
      var arr = [];
      var total = 0;
      for (var i = 0; i < 1000; i++) {
        arr[i] = i+1;
      }
    
      function someFn(i) {
        return i * 3 * 8;
      }

Test runner

Ready to run.

Testing in
TestOps/sec
Array.ForEach
arr.forEach(function(item) {
  total += someFn(item);
})
ready
For
for (var i = 0, len = arr.length; i < len; i++) {
  total += someFn(arr[i]);
}
ready
alternate For
for (var i = 0, item; item = arr[i]; ++i) {
  total += someFn(item);
}
ready
alternate For
var len = arr.length;

for (var i = 0, len; i < len; i++) {
  total += someFn(arr[i]);
}
ready
alternate For
for (var i in arr) {
  total += someFn(arr[i]);
}
ready
with lint compliance
for (var i = 0, len=arr.length, item; i<len; item=arr[++i]) {
  total += someFn(item);
}
ready

Revisions

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