Loop vs map vs forEach (v5)

Revision 5 of this benchmark created on


Setup

var range = [];
  
  for (var i = 0; i < 10000; i++) {
      range.push(i);
  }

Test runner

Ready to run.

Testing in
TestOps/sec
Loop
for (var i = 0; i < range.length; i++) {
    var a = range[i];
}
ready
Map
var result = range.map(function(val) { val; });
ready
forEach
range.forEach(function(val) {
    val;
});
ready

Revisions

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