Custom Loop

Benchmark created by hdez on


Description

Testing a custom loop method

Setup

var collection = [];
    var b = [];
    for(var i = 0; i < 10000; i++){
    collection.push(i + "a");
    }
    
    //Custom looping function
    function loop(a, method){
      var i = -1,
          length = (a.length - 1);
      while(i++ !== length){
        method(i);
      }
    }

Test runner

Ready to run.

Testing in
TestOps/sec
For loop
var l = collection.length;
for(var i = 0; i < l; i++){
b.push(i);
}
ready
While loop
var i = -1,
l = (collection.length-1);
while(i++ !== l){
b.push(i);
}
ready
Loop()
function go(n){
  b.push(n);
}

loop(collection,go);
ready

Revisions

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