-
-
Notifications
You must be signed in to change notification settings - Fork 231
/
benchmark-bench.js
92 lines (86 loc) · 2.08 KB
/
benchmark-bench.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
'use strict'
import inquirer from 'inquirer'
import bench from './lib/bench.js'
import { choices, list } from './lib/packages.js'
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()
return bench(options, modules)
}
async function getBenchmarkOptions () {
if (argv.length) return parseArgv()
return inquirer.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: 100,
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: 10,
validate (value) {
return !Number.isNaN(parseFloat(value)) || 'Please enter a number'
},
filter: Number
},
{
type: 'input',
name: 'duration',
message: 'How long should it take?',
default: 40,
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 inquirer.prompt([
{
type: 'checkbox',
message: 'Select packages',
name: 'list',
choices: [
new inquirer.Separator(' = The usual ='),
...list(),
new inquirer.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
}