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

Revision 5 of this benchmark created by michaelbazos on


Preparation HTML

<script src="
//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.min.js"></script>
<script src="
//cdnjs.cloudflare.com/ajax/libs/ramda/0.19.0/ramda.min.js"></script>

Setup

var arr = Array.apply(null, Array(10000)).map(Number.prototype.valueOf, 0);
    var newArr = [];
    
    function addOne(val) {
      return val + 1;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
for loop
for (var i = 0, len = arr.length; i < len; i++) {
  newArr.push(addOne(arr[i]));
}
ready
map
newArr = arr.map(addOne)
ready
faster for
var result = new Array(arr.length);
for (var i = 0, l = arr.length; i < l; i++) {
  result[i] = addOne(arr[i]);
}
ready
lodash map
newArr = _.map(arr, addOne)
ready
ramda map
newArr = R.map(addOne, arr)
ready

Revisions

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