APTYPE01

JavaScript performance comparison

Test case created by hdez

Info

testing a custom forEach method

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    //array with 1 mil entries
    var a = [];
    for(var i = 0; i < 1000000; i++){
         a.push(i);
    }
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Naked While
var i = -1,
length = a.length - 1;
while(i++ !== length){
a[i] = a[i] * 2;
}
pending…
Custom For Each
Array.prototype.forEach = function(fn){
  var i = -1,
      length = this.length - 1;
  while(i++ !== length){
    fn(this[i]);
  }
}
a.forEach(function(entry){
entry = entry * 2;
});
pending…

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

Compare results of other browsers

0 comments

Add a comment