0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-22 07:37:56 +01:00
nodejs/benchmark/es/spread-assign.js
Marco Ippolito b5aae52c71
Revert "util: move util._extend to eol"
This reverts commit ac97a532f5.

PR-URL: https://github.com/nodejs/node/pull/53429
Refs: https://github.com/tape-testing/tape/issues/607
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: James M Snell <jasnell@gmail.com>
2024-06-14 13:07:58 +00:00

43 lines
898 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;
switch (method) {
case '_extend':
bench.start();
for (let i = 0; i < n; i++)
obj = util._extend({}, src);
bench.end(n);
break;
case 'assign':
bench.start();
for (let i = 0; i < n; i++)
obj = Object.assign({}, src);
bench.end(n);
break;
case 'spread':
bench.start();
for (let i = 0; i < n; i++)
obj = { ...src }; // eslint-disable-line no-unused-vars
bench.end(n);
break;
default:
throw new Error('Unexpected method');
}
}