array fn call

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var bigArray = [];
    var j = 0;
    for (var i = 0; i < 1000; i++) {
      bigArray.push(i);
    }
   
    var fn = function fn(item) {
      j = j + item
    }
   
    var reducefn = function(item, prev) {
      return item + prev;
    }
   
};
</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
for loop
for (var i = 0 ; i < bigArray.length ; i++) {
  fn(bigArray[i]);
}
 
pending…
for in
for (var i in bigArray) {
  fn(bigArray[i])
}
 
pending…
map
bigArray.map(fn)
 
pending…
reduce
j = bigArray.reduce(reducefn, 0)
pending…
bigArray.forEach(fn)
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