GeezerVison is showing github.com — benchmark: add util.parseArgs benchmark · nodejs/node@42e39a0
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +67Lines changed: 67 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | + | | 3 | +const util = require('node:util'); | | 4 | +const assert = require('node:assert'); | | 5 | +const common = require('../common'); | | 6 | + | | 7 | +const inputs = { | | 8 | + 'short-flags': { | | 9 | + args: ['-a', '-b', '-c'], | | 10 | + options: { | | 11 | + alpha: { type: 'boolean', short: 'a' }, | | 12 | + beta: { type: 'boolean', short: 'b' }, | | 13 | + gamma: { type: 'boolean', short: 'c' }, | | 14 | + }, | | 15 | + }, | | 16 | + 'long-flags': { | | 17 | + args: ['--foo', '--bar', '--baz'], | | 18 | + options: { | | 19 | + foo: { type: 'boolean' }, | | 20 | + bar: { type: 'boolean' }, | | 21 | + baz: { type: 'boolean' }, | | 22 | + }, | | 23 | + }, | | 24 | + 'values': { | | 25 | + args: ['--foo=1', '--bar', '2', '-b', '3'], | | 26 | + options: { | | 27 | + foo: { type: 'string' }, | | 28 | + bar: { type: 'string' }, | | 29 | + baz: { type: 'string', short: 'b' }, | | 30 | + }, | | 31 | + }, | | 32 | + 'non-strict': { | | 33 | + args: ['--foo', '--unknown=value', '-x', 'file.js', 'other.js'], | | 34 | + options: { | | 35 | + foo: { type: 'boolean' }, | | 36 | + }, | | 37 | + strict: false, | | 38 | + }, | | 39 | + 'tokens': { | | 40 | + args: ['-ab', '--foo=1', '--bar', '2', 'file.js'], | | 41 | + options: { | | 42 | + alpha: { type: 'boolean', short: 'a' }, | | 43 | + beta: { type: 'boolean', short: 'b' }, | | 44 | + foo: { type: 'string' }, | | 45 | + bar: { type: 'string' }, | | 46 | + }, | | 47 | + allowPositionals: true, | | 48 | + tokens: true, | | 49 | + }, | | 50 | +}; | | 51 | + | | 52 | +const bench = common.createBenchmark(main, { | | 53 | + n: [1e5], | | 54 | + type: Object.keys(inputs), | | 55 | +}); | | 56 | + | | 57 | +function main({ n, type }) { | | 58 | + const config = inputs[type]; | | 59 | + let noDead; | | 60 | + | | 61 | + bench.start(); | | 62 | + for (let i = 0; i < n; i++) { | | 63 | + noDead = util.parseArgs(config); | | 64 | + } | | 65 | + bench.end(n); | | 66 | + assert(noDead !== undefined); | | 67 | +} |
|