mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
41e5253e7c
In the spread-assign.js benchmark file, all ESLint rules are disabled for a line where only no-unused-vars needs to be disabled. This change makes it so that the remaining rules are still applied to the line. PR-URL: https://github.com/nodejs/node/pull/21133 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
46 lines
987 B
JavaScript
46 lines
987 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common.js');
|
|
const util = require('util');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
method: ['spread', 'assign', '_extend'],
|
|
count: [5, 10, 20],
|
|
n: [1e6]
|
|
});
|
|
|
|
function main({ n, context, count, rest, method }) {
|
|
|
|
const src = {};
|
|
for (let n = 0; n < count; n++)
|
|
src[`p${n}`] = n;
|
|
|
|
let obj; // eslint-disable-line no-unused-vars
|
|
let i;
|
|
|
|
switch (method) {
|
|
case '':
|
|
// Empty string falls through to next line as default, mostly for tests.
|
|
case '_extend':
|
|
bench.start();
|
|
for (i = 0; i < n; i++)
|
|
obj = util._extend({}, src);
|
|
bench.end(n);
|
|
break;
|
|
case 'assign':
|
|
bench.start();
|
|
for (i = 0; i < n; i++)
|
|
obj = Object.assign({}, src);
|
|
bench.end(n);
|
|
break;
|
|
case 'spread':
|
|
bench.start();
|
|
for (i = 0; i < n; i++)
|
|
obj = { ...src };
|
|
bench.end(n);
|
|
break;
|
|
default:
|
|
throw new Error('Unexpected method');
|
|
}
|
|
}
|