curry cost (v6)

Revision 6 of this benchmark created by spion on


Preparation HTML

<script>
var _;

var curried = function(x){
  return function(y){
     return x + y;
  };
};

var precurried = curried(1);

var notcurried = _ = function(x, y){
   return x + y;
}; _._ = 2;

function F2(fun) {
    function wrapper(a) { return function(b) { return fun(a,b) } }
    wrapper.arity = 2;
    wrapper.func = fun;
    return wrapper;
}

function A2(fun,a,b) {
   return fun.arity === 2
            ? fun.func(a,b)
            : fun(a)(b);
}

elmcurried = F2(function(x, y){
   return x + y;
});

var _2 = function (f, a, b) {
  if (f._ === 2 || f.length === 2) {
    return f(a, b);
  }
};
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
curried
var s = 0;
for (var k = 0; k < 1000; ++k) {
  s += curried(1)(2);
}
if (s != 3000) die();
ready
not curried
var s = 0;
for (var k = 0; k < 1000; ++k) {
  s += notcurried(1, 2);
}
if (s != 3000) die();
ready
pre curried
var s = 0;
for (var k = 0; k < 1000; ++k) {
  s += precurried(2);
}
if (s != 3000) die();
ready
elm curried
var s = 0;
for (var k = 0; k < 1000; ++k) {
  s += A2(elmcurried, 1, 2)
}
if (s != 3000) die();
ready
TS curried
var s = 0;
for (var k = 0; k < 1000; ++k) {
  s += _2(notcurried, 1, 2)
}
if (s != 3000) die();
ready

Revisions

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