Curried Proxies

JavaScript performance comparison

Test case created by Scott Christopher

Preparation code

<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.17.1/ramda.min.js"></script>
      
<script>
Benchmark.prototype.setup = function() {
  function curryHandler(boundArgs) {
    return {
      apply: function (target, thisArg, argList) {
        var totalArgs = boundArgs.concat(argList);
        return totalArgs.length >= target.length ? target.apply(thisArg, totalArgs) : new Proxy(target, curryHandler(totalArgs));
      },
      get: function (target, prop, recv) {
        switch (prop) {
          case 'length':
            return target.length - boundArgs.length;
          case 'name':
            return target.name;
          default:
            return target[prop];
        }
      }
    }
  }
  
  function curry(fn) {
    return new Proxy(fn, curryHandler([]));
  }
  
  function _add3(a, b, c) {
    return a + b + c;
  }
  
  function test(fn) {
    var a = fn(1, 2, 3);
    var b = fn(a)(2)(3);
    var c = fn(b)(2, 3);
    var d = fn(c, 2)(3);
    return fn(d, 2, 3, 4);
  }

};
</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
Ramda
test(R.curry(_add3));
pending…
Native Proxy
test(curry(_add3));
pending…

Compare results of other browsers

Revisions

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

0 Comments