-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·205 lines (198 loc) · 5.37 KB
/
cli.js
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/usr/bin/env node
import { peowly } from 'peowly'
import pkg from './package.json' with { type: 'json' }
import {
baseline as baselineBenchmark,
bench as benchmark,
run,
} from './src/index.js'
import { spawnSync } from './src/lib.js'
const {
flags: { baseline, bench, ...flags },
} = peowly({
options: {
baseline: {
listGroup: 'Benchmark options',
description: 'Baseline command',
type: 'string',
short: 'B',
},
bench: {
listGroup: 'Benchmark options',
description: 'Benchmark command',
type: 'string',
multiple: true,
short: 'b',
},
samples: {
listGroup: 'Benchmark options',
description: 'Minimum number of samples',
type: 'string',
short: 's',
},
time: {
listGroup: 'Benchmark options',
description: 'Minimum time in nanoseconds',
type: 'string',
short: 't',
},
warmup: {
listGroup: 'Benchmark options',
description: 'Minimum number of warmup run(s)',
type: 'string',
short: 'w',
},
'warmup-time': {
listGroup: 'Benchmark options',
description: 'Minimum warmup run(s) time in nanoseconds',
type: 'string',
},
prepare: {
listGroup: 'Benchmark options',
description: 'Command to prepare benchmark(s)',
type: 'string',
},
before: {
listGroup: 'Benchmark options',
description: 'Command before each benchmark',
type: 'string',
},
after: {
listGroup: 'Benchmark options',
description: 'Command after each benchmark',
type: 'string',
},
'before-each': {
listGroup: 'Benchmark options',
description: 'Command before each iteration',
type: 'string',
},
'after-each': {
listGroup: 'Benchmark options',
description: 'Command after each iteration',
type: 'string',
},
silent: {
listGroup: 'Output options',
description: 'No standard output',
type: 'boolean',
},
json: {
listGroup: 'Output options',
description: 'Outputs as JSON',
type: 'string',
short: 'j',
},
file: {
listGroup: 'Output options',
description: 'Outputs as JSON to a file',
type: 'string',
short: 'f',
},
'no-colors': {
listGroup: 'Output options',
description: 'No colors in output',
type: 'boolean',
},
'no-latency': {
listGroup: 'Output options',
description: 'No time/iter column',
type: 'boolean',
},
'no-throughput': {
listGroup: 'Output options',
description: 'No iters/s column',
type: 'boolean',
},
'no-latency-min_max': {
listGroup: 'Output options',
description: 'No latency (min...max) column',
type: 'boolean',
},
'no-latency-percentiles': {
listGroup: 'Output options',
description: 'No latency percentile columns',
type: 'boolean',
},
units: {
listGroup: 'Output options',
description: 'Prints units cheatsheet',
type: 'boolean',
short: 'u',
},
},
description: 'tatami-ng CLI for running benchmark',
examples: ["--baseline '<command>' --bench '<command>' --bench '<command>'"],
name: 'tatami',
pkg,
})
if (baseline != null) {
baselineBenchmark(
baseline,
() => {
spawnSync(baseline)
},
{
...(flags.before != null && { before: () => spawnSync(flags.before) }),
...(flags.after != null && { after: () => spawnSync(flags.after) }),
...(flags['before-each'] != null && {
beforeEach: () => spawnSync(flags['before-each']),
}),
...(flags['after-each'] != null && {
afterEach: () => spawnSync(flags['after-each']),
}),
}
)
}
if (bench != null) {
for (const b of bench) {
benchmark(
b,
() => {
spawnSync(b)
},
{
...(flags.before != null && { before: () => spawnSync(flags.before) }),
...(flags.after != null && { after: () => spawnSync(flags.after) }),
...(flags['before-each'] != null && {
beforeEach: () => spawnSync(flags['before-each']),
}),
...(flags['after-each'] != null && {
afterEach: () => spawnSync(flags['after-each']),
}),
}
)
}
}
if (flags.json != null) {
const json = Number.parseInt(flags.json)
if (!Number.isNaN(json)) {
flags.json = json
}
}
if (flags.prepare != null) {
spawnSync(flags.prepare)
}
await run({
...(flags.samples != null && { samples: Number.parseInt(flags.samples) }),
...(flags.time != null && { time: Number.parseFloat(flags.time) }),
...(flags.warmup != null && { warmup: Number.parseInt(flags.warmup) }),
...(flags['warmup-time'] != null && {
warmupTime: Number.parseFloat(flags['warmup-time']),
}),
...(flags.silent != null && { silent: flags.silent }),
...(flags.json != null && { json: flags.json }),
...(flags.file != null && { file: flags.file }),
...(flags['no-colors'] != null && { colors: !flags['no-colors'] }),
...(flags['no-latency'] != null && { latency: !flags['no-latency'] }),
...(flags['no-throughput'] != null && {
throughput: !flags['no-throughput'],
}),
...(flags['no-latency-min_max'] != null && {
latencyMinMax: !flags['no-latency-min_max'],
}),
...(flags['no-latency-percentiles'] != null && {
latencyPercentiles: !flags['no-latency-percentiles'],
}),
...(flags.units != null && { units: flags.units }),
})