Single pass vs multiple passes

JavaScript performance comparison

Test case created by Brian

Info

This is the simple array fusion example from Rephrase:

https://github.com/puffnfresh/rephrase

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var array = [];
    var add1 = add(1);
    var add2 = add(2);
   
    function add(a) {
      return function(b) {
        return a + b;
      };
    }
   
    (function() {
      var size = 100000;
      var i;
   
      for (i = 0; i < size; i++) {
        array.push(1);
      }
    })();
};
</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
Multiple pass
array.map(add1).map(add2);
pending…
Single pass
array.map(function(x) {
  return add1(add2(x));
});
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

1 comment

Hayk Saakian commented :

Mul-ti-pass?

This data seems too close to call, I wish more people ran this jsperf.

Add a comment