mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 07:27:22 +01:00
29e74d4952
Code in benchmark directory sometimes uses `function () {}` for anonymous callbacks and sometimes uses `() => {}`. Multi-line arrays sometimes have a trailing comma and sometimes do not. Update to always use arrow functions for anonymous callbacks and trailing commas for multiline arrays. PR-URL: https://github.com/nodejs/node/pull/25944 Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
60 lines
1.1 KiB
JavaScript
60 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 }) {
|
|
var fn;
|
|
switch (method) {
|
|
// '' is a default case for tests
|
|
case '':
|
|
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 (var i = 0; i < n; i++)
|
|
fn('part 1', 'part', 2, 'part 3', 'part', 4);
|
|
bench.end(n);
|
|
}
|