Repository navigation
Expand file tree
/
Copy pathparse-args.js
More file actions
67 lines (62 loc) Β· 1.47 KB
/
Copy pathparse-args.js
File metadata and controls
67 lines (62 loc) Β· 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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);
}