-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark-bench.js
140 lines (132 loc) · 3.4 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
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
"use strict";
const inquirer = require("inquirer");
const bench = require("./lib/bench");
const serverBenchmarks = require("./lib/packages");
const mionBenchmarks = require("./lib/packages-mion-options");
const argv = process.argv.slice(2);
let choices;
let list;
let getBenchmarkInfo;
run().catch((err) => {
console.error("error general 2===>", err);
process.exit(1);
});
function setBenchmarks(benchmarkName) {
switch (benchmarkName) {
case "mion":
choices = mionBenchmarks.choices;
list = mionBenchmarks.list;
getBenchmarkInfo = mionBenchmarks.info;
break;
case "servers":
default:
choices = serverBenchmarks.choices;
list = serverBenchmarks.list;
getBenchmarkInfo = serverBenchmarks.info;
break;
}
}
async function run() {
const options = await getBenchmarkOptions();
setBenchmarks(options.benchmark);
const modules = options.all ? choices : await select();
return bench(options, modules, getBenchmarkInfo);
}
async function getBenchmarkOptions() {
if (argv.length) return parseArgv();
return inquirer.prompt([
{
type: "list",
message: "Select what benchmark do you want to run?",
name: "benchmark",
choices: [
{
name: "servers => compare multiple libraries (update User)",
value: "servers",
},
{
name: "servers => compare multiple libraries (hello world)",
value: "servers-hello",
},
// {
// name: "mion options => benchmarks mion using different settings and options",
// value: "mion",
// },
],
validate: function (answer) {
if (answer.length < 1) {
return "You must choose at least one benchmark.";
}
return true;
},
},
{
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, benchmark] = argv;
return {
all: all === "y",
connections: +connections,
pipelining: +pipelining,
duration: +duration,
benchmark,
};
}
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;
}