-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
129 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
yarn run v1.22.19 | ||
$ ts-node test/perf/parser.perf.ts | ||
simple x 103,392 ops/sec ±0.91% (77 runs sampled) | ||
multiple async flags that take time x 4.96 ops/sec ±0.13% (28 runs sampled) | ||
multiple async flags that take time x 5,451 ops/sec ±2.09% (79 runs sampled) | ||
Done in 21.11s. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright (c) 2023, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import {Suite} from 'benchmark' | ||
import {parse} from '../../src/parser' | ||
import {Flags} from '../../src' | ||
|
||
const suite = new Suite() | ||
|
||
// eslint-disable-next-line no-promise-executor-return | ||
const delay100 = () => new Promise(resolve => setTimeout(resolve, 100)) | ||
|
||
suite | ||
.add('simple', | ||
{ | ||
defer: true, | ||
fn: function (deferred: { resolve: () => any }) { | ||
parse(['--bool'], { | ||
flags: { | ||
bool: Flags.boolean(), | ||
}, | ||
}).then(() => deferred.resolve()) | ||
}, | ||
}) | ||
.add('multiple async flags that take time', { | ||
defer: true, | ||
fn: function (deferred: { resolve: () => any }) { | ||
parse(['--flagA', 'foo', '--flagA', 'bar'], { | ||
flags: { | ||
flagA: Flags.string({ | ||
parse: async input => { | ||
await delay100() | ||
return input | ||
}, | ||
}), | ||
flagB: Flags.string({ | ||
parse: async input => { | ||
await delay100() | ||
return input | ||
}, | ||
}), | ||
}, | ||
}).then(() => deferred.resolve()) | ||
}, | ||
}) | ||
|
||
.add('flagstravaganza', { | ||
defer: true, | ||
fn: function (deferred: { resolve: () => any }) { | ||
const flags = [ | ||
['--bool'], | ||
['-S', 'foo'], | ||
|
||
['--dep-string', 'foo'], | ||
['--excl-string', 'foo'], | ||
['--exactly-one', 'foo'], | ||
|
||
['--parsed-string-as-number', '5'], | ||
['--dir', process.cwd()], | ||
['--file', __filename], | ||
|
||
['--multiple', '1'], | ||
['--multiple', '2'], | ||
['--multiple', '3'], | ||
['--multiple2', '5,6,7,8,9,10,11'], | ||
] | ||
const exactlyOne = ['exactly-one-nope', 'exactly-one-nope2', 'exactly-one'] | ||
parse(flags.flat(), { | ||
flags: { | ||
bool: Flags.boolean(), | ||
string: Flags.string({char: 's', aliases: ['S']}), | ||
|
||
'dep-string': Flags.string({dependsOn: ['string']}), | ||
// don't populate this one, used for exclusive test | ||
nope: Flags.boolean(), | ||
'excl-string': Flags.string({exclusive: ['nope']}), | ||
'exactly-one-nope': Flags.string({exactlyOne}), | ||
'exactly-one-nope2': Flags.string({exactlyOne}), | ||
'exactly-one': Flags.string({exactlyOne}), | ||
|
||
'parsed-string-as-number': Flags.integer({parse: input => Promise.resolve(Number.parseInt(input, 10) + 1000)}), | ||
dir: Flags.directory({exists: true}), | ||
file: Flags.file({exists: true}), | ||
|
||
multiple: Flags.string({multiple: true}), | ||
multiple2: Flags.string({multiple: true, delimiter: ','}), | ||
}, | ||
}).then(() => deferred.resolve()) | ||
}, | ||
}) | ||
|
||
// add listeners | ||
.on('cycle', (event: any) => { | ||
console.log(String(event.target)) | ||
}) | ||
.run({async: true}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters