Using curryed methods

JavaScript performance comparison

Test case created by Carlos Vázquez

Preparation code

<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.23.0/ramda.min.js"></script>
      
<script>
Benchmark.prototype.setup = function() {
  function curry(f) {
    	var self = this;
    
    	return function() {
    		if (arguments.length >= f.length) {
    			return f.apply(self, arguments);
    		} else {
    			for (var g = f, i = 0, le = arguments.length; i < le; i++) {
    				g = g.bind(self, arguments[i]);
    			}
    			return curry(g);
    		}
    	};
    };
  
  
  addHandMadeFly = function(a, b) {
      if (b != undefined) {
          return a + b;
      }
      return function(c) {
          return a + c;
      }
  }
  
  addCustomCurry = curry(function(a, b) {
      return a + b;
  });
  
  addRamdaCurry = R.curry(function(a, b) {
      return a + b;
  });
  
  _addHandMadeBinding = function(a, b) {
      return a + b;
  }
  
  addHandMadeBinding = function(a, b) {
      if (b != undefined) {
          return a + b;
      } else {
          return _addHandMadeBinding.bind(this, a)
      }
  }

};
</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
Hand made (function on the fly)
addHandMadeFly(2, 1)
pending…
Custom curry
addCustomCurry(2, 1)
pending…
Ramda curry
addRamdaCurry(2, 1)
pending…
Hand made (binding other function)
addHandMadeBinding(2, 1)
pending…

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

0 Comments