@naturalcycles/bench-lib 1.6.8 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bench.model.d.ts +1 -2
- package/dist/bench.util.js +50 -44
- package/dist/cannon.model.d.ts +0 -1
- package/dist/cannon.util.js +82 -65
- package/package.json +5 -7
package/dist/bench.model.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export interface RunBenchOptions {
|
|
|
14
14
|
* How many times to run.
|
|
15
15
|
* Every second run will be in reverse order.
|
|
16
16
|
*
|
|
17
|
-
* @default
|
|
17
|
+
* @default 2
|
|
18
18
|
*/
|
|
19
19
|
runs?: number;
|
|
20
20
|
/**
|
|
@@ -46,7 +46,6 @@ export interface RunBenchOptions {
|
|
|
46
46
|
*
|
|
47
47
|
* @default true
|
|
48
48
|
*/
|
|
49
|
-
writePlot?: boolean;
|
|
50
49
|
/**
|
|
51
50
|
* Plot ascii chart in the terminal:)
|
|
52
51
|
*
|
package/dist/bench.util.js
CHANGED
|
@@ -5,8 +5,6 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
6
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
7
7
|
const benchmark_1 = tslib_1.__importDefault(require("benchmark"));
|
|
8
|
-
const vega_1 = tslib_1.__importDefault(require("vega"));
|
|
9
|
-
const vega_lite_1 = tslib_1.__importDefault(require("vega-lite"));
|
|
10
8
|
const asciiChart_util_1 = require("./asciiChart.util");
|
|
11
9
|
/**
|
|
12
10
|
* Wraps `runBench` in `runScript` for convenience, so it can be run in top-level without `await`.
|
|
@@ -24,7 +22,7 @@ exports.runBenchScript = runBenchScript;
|
|
|
24
22
|
* Only DeferredFunctions are allowed, because of: https://github.com/bestiejs/benchmark.js/issues/111
|
|
25
23
|
*/
|
|
26
24
|
async function runBench(opt) {
|
|
27
|
-
const { runs =
|
|
25
|
+
const { runs = 2, writeSummary = true, asciiPlot = true, name = 'runBench' } = opt;
|
|
28
26
|
const { reportDirPath = `./tmp/${name}` } = opt;
|
|
29
27
|
console.log(`running benchmark...\n\n`);
|
|
30
28
|
const results = [];
|
|
@@ -50,15 +48,18 @@ async function runBench(opt) {
|
|
|
50
48
|
nodejs_lib_1.fs2.writeJson(summaryJsonPath, avg, { spaces: 2 });
|
|
51
49
|
console.log(`saved ${(0, nodejs_lib_1.dimGrey)(summaryJsonPath)}`);
|
|
52
50
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
51
|
+
// Vega plots are currently disabled
|
|
52
|
+
// if (writePlot) {
|
|
53
|
+
// fs2.ensureDir(reportDirPath)
|
|
54
|
+
//
|
|
55
|
+
// const spec = benchResultsToVegaSpec(avg)
|
|
56
|
+
// const view = new vega.View(vega.parse(spec), { renderer: 'none' })
|
|
57
|
+
// const svg = await view.toSVG()
|
|
58
|
+
//
|
|
59
|
+
// const plotPath = `${reportDirPath}/${name}.svg`
|
|
60
|
+
// fs2.writeFile(plotPath, svg)
|
|
61
|
+
// console.log(`saved ${dimGrey(plotPath)}`)
|
|
62
|
+
// }
|
|
62
63
|
if (asciiPlot) {
|
|
63
64
|
console.log('\n' + (0, asciiChart_util_1.plotAsciiChart)(avg));
|
|
64
65
|
}
|
|
@@ -100,38 +101,43 @@ async function runBenchOnce(opt, run) {
|
|
|
100
101
|
});
|
|
101
102
|
return await defer;
|
|
102
103
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
104
|
+
/*
|
|
105
|
+
function benchResultsToVegaSpec(map: HertzMap): Spec {
|
|
106
|
+
const values = Object.entries(map).map(([name, hz]) => {
|
|
107
|
+
return {
|
|
108
|
+
name,
|
|
109
|
+
hz,
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
// console.log(values)
|
|
114
|
+
|
|
115
|
+
const liteSpec: TopLevelSpec = {
|
|
116
|
+
// title: 'title',
|
|
117
|
+
// "$schema": "https://vega.github.io/schema/vega-lite/v3.json",
|
|
118
|
+
data: {
|
|
119
|
+
values,
|
|
120
|
+
},
|
|
121
|
+
mark: 'bar',
|
|
122
|
+
encoding: {
|
|
123
|
+
y: {
|
|
124
|
+
field: 'name',
|
|
125
|
+
type: 'ordinal',
|
|
126
|
+
axis: {
|
|
127
|
+
title: '',
|
|
116
128
|
},
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
title: '',
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
x: {
|
|
127
|
-
field: 'hz',
|
|
128
|
-
type: 'quantitative',
|
|
129
|
-
axis: {
|
|
130
|
-
title: 'ops/sec',
|
|
131
|
-
},
|
|
132
|
-
},
|
|
129
|
+
},
|
|
130
|
+
x: {
|
|
131
|
+
field: 'hz',
|
|
132
|
+
type: 'quantitative',
|
|
133
|
+
axis: {
|
|
134
|
+
title: 'ops/sec',
|
|
133
135
|
},
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const { spec } = vegaLite.compile(liteSpec)
|
|
141
|
+
return spec
|
|
137
142
|
}
|
|
143
|
+
*/
|
package/dist/cannon.model.d.ts
CHANGED
package/dist/cannon.util.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runCannon = exports.runCannonScript = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
5
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
7
|
-
const vega_1 = tslib_1.__importDefault(require("vega"));
|
|
8
|
-
const vega_lite_1 = tslib_1.__importDefault(require("vega-lite"));
|
|
9
6
|
/**
|
|
10
7
|
* Wraps `runBench` in `runScript` for convenience, so it can be run in top-level without `await`.
|
|
11
8
|
*/
|
|
@@ -22,7 +19,6 @@ async function runCannon(profiles, optInput = {}) {
|
|
|
22
19
|
const opt = {
|
|
23
20
|
name: 'Benchmark',
|
|
24
21
|
reportDirPath: `./tmp/${optInput.name || 'Benchmark'}`,
|
|
25
|
-
writePlots: true,
|
|
26
22
|
writeSummary: true,
|
|
27
23
|
writeRawSummary: true,
|
|
28
24
|
runs: 2,
|
|
@@ -72,9 +68,9 @@ async function runCannon(profiles, optInput = {}) {
|
|
|
72
68
|
if (opt.writeRawSummary) {
|
|
73
69
|
nodejs_lib_1.fs2.writeJson(`${reportDirPath}/${opt.name}.rawSummary.json`, resultByProfile, { spaces: 2 });
|
|
74
70
|
}
|
|
75
|
-
if (opt.writePlots) {
|
|
76
|
-
|
|
77
|
-
}
|
|
71
|
+
// if (opt.writePlots) {
|
|
72
|
+
// await writePlotFiles(opt, summaries)
|
|
73
|
+
// }
|
|
78
74
|
return summaries;
|
|
79
75
|
}
|
|
80
76
|
exports.runCannon = runCannon;
|
|
@@ -132,64 +128,85 @@ function toSummary(name, result) {
|
|
|
132
128
|
'2xx': result['2xx'],
|
|
133
129
|
};
|
|
134
130
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
131
|
+
/*
|
|
132
|
+
async function writePlotFiles(
|
|
133
|
+
opt: RunCannonNormalizedOptions,
|
|
134
|
+
summaries: AutocannonSummary[],
|
|
135
|
+
): Promise<void> {
|
|
136
|
+
const { reportDirPath, name } = opt
|
|
137
|
+
fs2.ensureDir(reportDirPath)
|
|
138
|
+
|
|
139
|
+
let fields = ['rpsAvg', 'latencyAvg', 'latency50', 'latency90', 'latency99', 'throughputAvg']
|
|
140
|
+
if (!opt.includeLatencyPercentiles) {
|
|
141
|
+
fields = fields.filter(f => !f.startsWith('latency') || f === 'latencyAvg')
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const specs = autocannonSummaryToVegaSpecs(fields, summaries)
|
|
145
|
+
|
|
146
|
+
await pMap(Object.keys(specs), async specName => {
|
|
147
|
+
// create a new view instance for a given Vega JSON spec
|
|
148
|
+
const view = new vega.View(vega.parse(specs[specName]!), { renderer: 'none' })
|
|
149
|
+
|
|
150
|
+
// generate a static SVG image
|
|
151
|
+
const svg = await view.toSVG()
|
|
152
|
+
// console.log(svg)
|
|
153
|
+
|
|
154
|
+
fs2.writeFile(`${reportDirPath}/${name}.${specName}.svg`, svg)
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
fs2.writeFile(`${reportDirPath}/${name}.md`, mdContent(opt, Object.keys(specs)))
|
|
152
158
|
}
|
|
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
|
-
|
|
159
|
+
|
|
160
|
+
function autocannonSummaryToVegaSpecs(
|
|
161
|
+
fields: string[],
|
|
162
|
+
summaries: AutocannonSummary[],
|
|
163
|
+
): StringMap<Spec> {
|
|
164
|
+
// console.log(summary)
|
|
165
|
+
|
|
166
|
+
const specs: StringMap<Spec> = {}
|
|
167
|
+
|
|
168
|
+
fields.forEach(field => {
|
|
169
|
+
const liteSpec: TopLevelSpec = {
|
|
170
|
+
// title: 'title',
|
|
171
|
+
// "$schema": "https://vega.github.io/schema/vega-lite/v3.json",
|
|
172
|
+
data: {
|
|
173
|
+
values: summaries,
|
|
174
|
+
},
|
|
175
|
+
mark: 'bar',
|
|
176
|
+
encoding: {
|
|
177
|
+
y: {
|
|
178
|
+
field: 'name',
|
|
179
|
+
type: 'ordinal',
|
|
180
|
+
axis: {
|
|
181
|
+
title: '',
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
x: {
|
|
185
|
+
field,
|
|
186
|
+
type: 'quantitative',
|
|
187
|
+
axis: {
|
|
188
|
+
title: field,
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const { spec } = vegaLite.compile(liteSpec)
|
|
195
|
+
specs[field] = spec
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
return specs
|
|
185
199
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
]
|
|
193
|
-
|
|
194
|
-
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
function mdContent(opt: RunCannonNormalizedOptions, specNames: string[]): string {
|
|
203
|
+
return [
|
|
204
|
+
`# ${opt.name}`,
|
|
205
|
+
opt.beforeText,
|
|
206
|
+
specNames.map(specName => ``).join('\n'),
|
|
207
|
+
opt.afterText,
|
|
208
|
+
]
|
|
209
|
+
.filter(Boolean)
|
|
210
|
+
.join('\n\n')
|
|
195
211
|
}
|
|
212
|
+
*/
|
package/package.json
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/bench-lib",
|
|
3
3
|
"scripts": {
|
|
4
|
-
"prepare": "husky
|
|
4
|
+
"prepare": "husky"
|
|
5
5
|
},
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@naturalcycles/js-lib": "^14.0.0",
|
|
8
8
|
"@naturalcycles/nodejs-lib": "^13.0.2",
|
|
9
9
|
"autocannon": "^7.0.0",
|
|
10
|
-
"benchmark": "^2.1.4"
|
|
11
|
-
"express": "^4.17.1",
|
|
12
|
-
"helmet": "^7.0.0",
|
|
13
|
-
"vega": "^5.10.1",
|
|
14
|
-
"vega-lite": "^5.0.0"
|
|
10
|
+
"benchmark": "^2.1.4"
|
|
15
11
|
},
|
|
16
12
|
"devDependencies": {
|
|
17
13
|
"@naturalcycles/dev-lib": "^13.6.0",
|
|
18
14
|
"@types/benchmark": "^2.1.0",
|
|
19
15
|
"@types/express": "^4.17.6",
|
|
20
16
|
"@types/node": "^20.1.0",
|
|
17
|
+
"express": "^4.17.1",
|
|
21
18
|
"fastify": "^4.6.0",
|
|
19
|
+
"helmet": "^7.0.0",
|
|
22
20
|
"jest": "^29.0.3"
|
|
23
21
|
},
|
|
24
22
|
"files": [
|
|
@@ -36,7 +34,7 @@
|
|
|
36
34
|
"engines": {
|
|
37
35
|
"node": ">=18.12.0"
|
|
38
36
|
},
|
|
39
|
-
"version": "1.
|
|
37
|
+
"version": "2.1.0",
|
|
40
38
|
"description": "Benchmarking library, based on Benchmark.js and Autocannon",
|
|
41
39
|
"author": "Natural Cycles Team",
|
|
42
40
|
"license": "MIT"
|