Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:83.0) Gecko/20100101 Firefox/83.0
Firefox 83
Mac OS X 10.16
Desktop
4 years ago
Test name Executions per second
rest with 10 args 7593549.5 Ops/sec
rest with 1 arg 15670709.0 Ops/sec
argsToArray with 10 args 4001228.5 Ops/sec
argsToArray with 1 arg 8999644.0 Ops/sec
Script Preparation code:
x
 
function rest(...args) {
  return function(fn) {
    return args.map(fn);
  };
}
function argsToArray() {
  const len = arguments.length;
  const args = Array(len);
  for (let i = 0; i < len; i++) {
    args[i] = arguments[i];
  }
  return function(fn) {
    return args.map(fn);
  };
}
Tests:
  • rest with 10 args

     
    rest(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)(n => 2 * n);
  • rest with 1 arg

     
    rest(1)(n => 2 * n);
  • argsToArray with 10 args

     
    argsToArray(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)(n => 2 * n);
  • argsToArray with 1 arg

     
    argsToArray(1)(n => 2 * n);