custom array forEach (v3)

Revision 3 of this benchmark created by william malo on


Setup

var array=["foo","bar","baz","lorem","ipsum","lol","cat"];
  
  var func=function(){2+2};
  
  Array.prototype.forEach2=function(a){
    var l=this.length,i=0;
    for(;i<l;i++)a(this[i],i)
  }
  
  Array.prototype.map2=function(a){
  var l=this.length,array=new Array(l),i=0;
  for(;i<l;i++){array[i]=a(this[i],i)}
  return array;
  }
  
  Array.prototype.map3=function(a){
  var l=this.length,array=[],i=0;
  for(;i<l;i++){array[i]=a(this[i],i)}
  return array;
  }

Test runner

Ready to run.

Testing in
TestOps/sec
map3
array.map3(func)
ready
foreach
array.forEach(func)
ready
custom foreach
array.forEach2(func)
ready
map
array.map(func)
ready
custom map
array.map2(func)
ready

Revisions

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