-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark-bench.mjs
98 lines (91 loc) · 2.26 KB
/
benchmark-bench.mjs
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
'use strict'
import { createRequire } from 'module'
import bench from './lib/bench.mjs'
import { choices, list } from './lib/packages.mjs'
const require = createRequire(import.meta.url)
import inquirer from 'inquirer'
const prompt = inquirer.prompt
const Separator = inquirer.Separator
// const { prompt, Separator } = require('inquirer')
const argv = process.argv.slice(2)
run().catch(err => {
console.error(err)
process.exit(1)
})
async function run () {
const options = await getBenchmarkOptions()
const modules = options.all ? choices : await select(list)
return bench(options, modules)
}
async function getBenchmarkOptions () {
if (argv.length) return parseArgv()
return prompt([
{
type: 'confirm',
name: 'all',
message: 'Do you want to run all benchmark tests?',
default: false
},
{
type: 'input',
name: 'connections',
message: 'How many connections do you need?',
default: 50,
validate (value) {
return !Number.isNaN(parseFloat(value)) || 'Please enter a number'
},
filter: Number
},
{
type: 'input',
name: 'pipelining',
message: 'How many pipelines do you need?',
default: 5,
validate (value) {
return !Number.isNaN(parseFloat(value)) || 'Please enter a number'
},
filter: Number
},
{
type: 'input',
name: 'duration',
message: 'How long should it take?',
default: 20,
validate (value) {
return !Number.isNaN(parseFloat(value)) || 'Please enter a number'
},
filter: Number
}
])
}
function parseArgv () {
const [all, connections, pipelining, duration] = argv
return {
all: all === 'y',
connections: +connections,
pipelining: +pipelining,
duration: +duration
}
}
async function select () {
const result = await prompt([
{
type: 'checkbox',
message: 'Select packages',
name: 'list',
choices: [
new Separator(' = The usual ='),
...list(),
new Separator(' = The extras = '),
...list(true)
],
validate: function (answer) {
if (answer.length < 1) {
return 'You must choose at least one package.'
}
return true
}
}
])
return result.list
}