mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
benchmark: add util.parseArgs benchmark
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com> PR-URL: https://github.com/nodejs/node/pull/66599 Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
1 parent
6c84c341bd
commit
17fa5deb23
1 file changed
+67
@@ -0,0 +1,67 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const util = require('node:util');
|
||||||
|
const assert = require('node:assert');
|
||||||
|
const common = require('../common');
|
||||||
|
|
||||||
|
const inputs = {
|
||||||
|
'short-flags': {
|
||||||
|
args: ['-a', '-b', '-c'],
|
||||||
|
options: {
|
||||||
|
alpha: { type: 'boolean', short: 'a' },
|
||||||
|
beta: { type: 'boolean', short: 'b' },
|
||||||
|
gamma: { type: 'boolean', short: 'c' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'long-flags': {
|
||||||
|
args: ['--foo', '--bar', '--baz'],
|
||||||
|
options: {
|
||||||
|
foo: { type: 'boolean' },
|
||||||
|
bar: { type: 'boolean' },
|
||||||
|
baz: { type: 'boolean' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'values': {
|
||||||
|
args: ['--foo=1', '--bar', '2', '-b', '3'],
|
||||||
|
options: {
|
||||||
|
foo: { type: 'string' },
|
||||||
|
bar: { type: 'string' },
|
||||||
|
baz: { type: 'string', short: 'b' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'non-strict': {
|
||||||
|
args: ['--foo', '--unknown=value', '-x', 'file.js', 'other.js'],
|
||||||
|
options: {
|
||||||
|
foo: { type: 'boolean' },
|
||||||
|
},
|
||||||
|
strict: false,
|
||||||
|
},
|
||||||
|
'tokens': {
|
||||||
|
args: ['-ab', '--foo=1', '--bar', '2', 'file.js'],
|
||||||
|
options: {
|
||||||
|
alpha: { type: 'boolean', short: 'a' },
|
||||||
|
beta: { type: 'boolean', short: 'b' },
|
||||||
|
foo: { type: 'string' },
|
||||||
|
bar: { type: 'string' },
|
||||||
|
},
|
||||||
|
allowPositionals: true,
|
||||||
|
tokens: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const bench = common.createBenchmark(main, {
|
||||||
|
n: [1e5],
|
||||||
|
type: Object.keys(inputs),
|
||||||
|
});
|
||||||
|
|
||||||
|
function main({ n, type }) {
|
||||||
|
const config = inputs[type];
|
||||||
|
let noDead;
|
||||||
|
|
||||||
|
bench.start();
|
||||||
|
for (let i = 0; i < n; i++) {
|
||||||
|
noDead = util.parseArgs(config);
|
||||||
|
}
|
||||||
|
bench.end(n);
|
||||||
|
assert(noDead !== undefined);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user