custom array forEach

JavaScript performance comparison

Test case created by william malo

Preparation code


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

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
for
(function(){
for(var i=array.length;i--;)2+2;
})()
pending…
foreach
array.forEach(func)
pending…
custom foreach
array.forEach2(func)
pending…
map
array.map(func)
pending…
custom map
array.map2(func)
pending…

Compare results of other browsers

Revisions

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

0 Comments