forked from fastify/benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 84
/
benchmark-bench.js
82 lines (77 loc) · 1.9 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
#!/usr/bin/env node
const bench = require("./lib/bench");
const { choices } = require("./lib/choices");
async function getInquirer() {
const { default: inquirer } = await import("inquirer");
return inquirer;
}
function select(callback) {
getInquirer()
.then((inquirer) => {
return inquirer.prompt([
{
type: "checkbox",
message: "Select packages",
name: "list",
choices: [...choices.map((name) => ({ name }))],
validate(answer) {
if (answer.length < 1) {
return "You must choose at least one package.";
}
return true;
},
},
]);
})
.then((answers) => {
callback(answers.list);
});
}
getInquirer()
.then((inquirer) => {
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: 5,
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: 1,
validate(value) {
return !Number.isNaN(parseFloat(value)) || "Please enter a number";
},
filter: Number,
},
{
type: "input",
name: "duration",
message: "How long should it take?",
default: 5,
validate(value) {
return !Number.isNaN(parseFloat(value)) || "Please enter a number";
},
filter: Number,
},
]);
})
.then((opts) => {
if (!opts.all) {
select((list) => bench(opts, list));
} else {
bench(opts, choices);
}
});