map vs native for loop (v16)

Revision 16 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

var v;
    
    testArray = new Array(100);
    for(var i = 0; i < 100; i++) {
      testArray[i] = i;
    }
    
    map = function(array) {
      v = 0;  
      for(var i = 0; i < array.length; i++) {
        v += array[i];
      } 
    }
    
    map2 = function(array) {
      v = 0;
      var length = array.length;
      for(var i = 0; i < length ; i++) {
        v += array[i];
      }
    }
    
    map3 = function(array) {
      v = 0;
      for(var i in array) {
        v += array[i];
      }
    }

Test runner

Ready to run.

Testing in
TestOps/sec
jquery map
v = 0;
var result = $.map(testArray, function(i){v += i;});
ready
for loop
var result = map(testArray);
ready
clever for loop
var result = map2(testArray);
ready
js map
v = 0;
var result = testArray.map(function(i){v += i;});
ready
iterate
var result = map3(testArray);
ready

Revisions

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