node/benchmark/error/format-list.js
Aras Abbasi 4f84a3d200
errors: improve formatList in errors.js
PR-URL: https://github.com/nodejs/node/pull/49642
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2023-09-29 11:04:38 +00:00

45 lines
659 B
JavaScript

'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
n: [1e7],
input: [
'',
'a',
'a,b',
'a,b,c',
'a,b,c,d',
],
type: [
'undefined',
'and',
'or',
],
}, {
flags: ['--expose-internals'],
});
function main({ n, input, type }) {
const {
formatList,
} = require('internal/errors');
const list = input.split(',');
if (type === 'undefined') {
bench.start();
for (let i = 0; i < n; ++i) {
formatList(list);
}
bench.end(n);
return;
}
bench.start();
for (let i = 0; i < n; ++i) {
formatList(list, type);
}
bench.end(n);
}