for loop vs Array.prototype.map() (v7)

Revision 7 of this benchmark created by bfricka on


Description

For some reason current Chrome is deopting when using push, so we're seeing really bad tests (+/- 30% margins = bad test).

Setup

var arr = [];
    var arrLen = 1000;
    while (arrLen--) arr.push(1);
    var newArr = Array(arr.length);
    
    function addOne(val) {
      return val + 1;
    }

Teardown


    arr = arrLen = newArr = addOne = null;
  

Test runner

Ready to run.

Testing in
TestOps/sec
for loop
for (var i = 0, len = arr.length; i < len; i++) {
  newArr[i] = addOne(arr[i]);
}
ready
map
newArr = arr.map(addOne)
ready

Revisions

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