using curried methods 2

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 curryFor(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 curryFor(g);
      		}
      	};
      };
    
    function curry(f) {
    	var self = this;
    
    	return function() {
        var al = arguments.length;
    		if (al >= f.length) {
    			return f.apply(self, arguments);
    		} else {
          g = f;
          g = g.bind(self, Array.prototype.slice.call(arguments, al));
    			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)
        }
    }
  
  _addHandMadeAuto = function(a, b) {
      return a + b;
  }
  
  addHandMadeAuto = function(a, b) {
      if (b != undefined) {
          return _addHandMadeAuto(a, b);
      } else {
          return function(c) {
             _addHandMadeAuto(a, c)
          }
      }
  }

};
</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…
Hand made automatic
addHandMadeAuto(2)(1)
pending…

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

0 Comments