map vs native for loop (v9)

Revision 9 of this benchmark created by Grdn on


Description

test the performance of the jquery map versus a native for loop map

Preparation HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js"></script>

Setup

testArray = new Array(100);
    for(var i = 0; i < 100; i++) {
      testArray[i] = i;
    }
    
    map = function(array, mapFunction) {
      var newArray = new Array(array.length);
      for(var i = 0; i < array.length; i++) {
        newArray[i] = mapFunction(array[i]);
      }
    
      return newArray;
    }
    
    double =function(x) {
      return x*2;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
jquery map
var result = _.map(testArray, double);
ready
for loop map
var result = map(testArray, double);
ready

Revisions

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