map vs native for loop (v34)

Revision 34 of this benchmark created on


Description

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

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.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
for loop
var result = [];

for (var i = 0; i < testArray.length; i++) {
  result.push(double(testArray[i]));
}
ready
array.map
var result = testArray.map(double);
ready

Revisions

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