Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36
Chrome 63
Mac OS X 10.13.2
Other
7 years ago
Test name Executions per second
rest with 10 args 7438530.0 Ops/sec
rest with 1 arg 10029255.0 Ops/sec
argsToArray with 10 args 1793108.8 Ops/sec
argsToArray with 1 arg 2654654.2 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);