0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-22 07:37:56 +01:00
nodejs/benchmark/util/splice-one.js
Liu Jia f8c27e6176
benchmark: update iterations in benchmark/util/splice-one.js
Increase the number of iterations from 1e5 to 5e6
to avoid the test performance gap caused by inactive
V8 optimization caused by insufficient number of iterations

Refs: https://github.com/nodejs/node/issues/50571
PR-URL: https://github.com/nodejs/node/pull/50698
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
2023-11-26 13:42:55 +00:00

34 lines
651 B
JavaScript

'use strict';
const common = require('../common');
const bench = common.createBenchmark(main, {
n: [5e6],
pos: ['start', 'middle', 'end'],
size: [10, 100, 500],
}, { flags: ['--expose-internals'] });
function main({ n, pos, size }) {
const { spliceOne } = require('internal/util');
const arr = new Array(size);
arr.fill('');
let index;
switch (pos) {
case 'end':
index = size - 1;
break;
case 'middle':
index = Math.floor(size / 2);
break;
default: // start
index = 0;
}
bench.start();
for (let i = 0; i < n; i++) {
spliceOne(arr, index);
arr.push('');
}
bench.end(n);
}