0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-28 14:33:11 +01:00
nodejs/benchmark/misc/arguments.js
Ruben Bridgewater bb6125bac7
benchmark: remove special test entries
This reverts commit 7cfbc9f90f.

PR-URL: https://github.com/nodejs/node/pull/31755
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2020-03-09 22:35:54 +01:00

58 lines
1.1 KiB
JavaScript

'use strict';
const { createBenchmark } = require('../common.js');
const { format } = require('util');
const methods = [
'restAndSpread',
'argumentsAndApply',
'restAndApply',
'predefined',
];
const bench = createBenchmark(main, {
method: methods,
n: [1e6]
});
function usingRestAndSpread(...args) {
format(...args);
}
function usingRestAndApply(...args) {
format.apply(null, args);
}
function usingArgumentsAndApply() {
format.apply(null, arguments);
}
function usingPredefined() {
format('part 1', 'part', 2, 'part 3', 'part', 4);
}
function main({ n, method, args }) {
let fn;
switch (method) {
case 'restAndSpread':
fn = usingRestAndSpread;
break;
case 'restAndApply':
fn = usingRestAndApply;
break;
case 'argumentsAndApply':
fn = usingArgumentsAndApply;
break;
case 'predefined':
fn = usingPredefined;
break;
default:
throw new Error(`Unexpected method "${method}"`);
}
bench.start();
for (let i = 0; i < n; i++)
fn('part 1', 'part', 2, 'part 3', 'part', 4);
bench.end(n);
}