@naturalcycles/bench-lib 3.0.0 → 3.1.1
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/asciiChart.util.js +1 -2
- package/dist/bench.util.js +5 -5
- package/dist/cannon.model.d.ts +0 -2
- package/dist/cannon.profiles.js +8 -8
- package/dist/cannon.util.js +4 -5
- package/dist/vendor/asciichart.js +7 -13
- package/package.json +20 -15
package/dist/asciiChart.util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.plotAsciiChart =
|
|
3
|
+
exports.plotAsciiChart = plotAsciiChart;
|
|
4
4
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
5
|
const asciichart_1 = require("./vendor/asciichart");
|
|
6
6
|
const colors = [
|
|
@@ -35,7 +35,6 @@ function plotAsciiChart(results) {
|
|
|
35
35
|
.join('\n');
|
|
36
36
|
return s;
|
|
37
37
|
}
|
|
38
|
-
exports.plotAsciiChart = plotAsciiChart;
|
|
39
38
|
function colored(char, color) {
|
|
40
39
|
if (!color)
|
|
41
40
|
return char;
|
package/dist/bench.util.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.runBenchScript = runBenchScript;
|
|
4
|
+
exports.runBench = runBench;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
5
6
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
7
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
@@ -17,7 +18,6 @@ function runBenchScript(opt) {
|
|
|
17
18
|
clearTimeout(timeout);
|
|
18
19
|
});
|
|
19
20
|
}
|
|
20
|
-
exports.runBenchScript = runBenchScript;
|
|
21
21
|
/**
|
|
22
22
|
* Only DeferredFunctions are allowed, because of: https://github.com/bestiejs/benchmark.js/issues/111
|
|
23
23
|
*/
|
|
@@ -26,7 +26,7 @@ async function runBench(opt) {
|
|
|
26
26
|
const { reportDirPath = `./tmp/${name}` } = opt;
|
|
27
27
|
console.log(`running benchmark...\n\n`);
|
|
28
28
|
const results = [];
|
|
29
|
-
for
|
|
29
|
+
for (const run of (0, js_lib_1._range)(1, runs + 1)) {
|
|
30
30
|
results.push(await runBenchOnce(opt, run));
|
|
31
31
|
}
|
|
32
32
|
const avg = {};
|
|
@@ -65,11 +65,11 @@ async function runBench(opt) {
|
|
|
65
65
|
}
|
|
66
66
|
return avg;
|
|
67
67
|
}
|
|
68
|
-
exports.runBench = runBench;
|
|
69
68
|
async function runBenchOnce(opt, run) {
|
|
70
69
|
const defer = (0, js_lib_1.pDefer)();
|
|
71
70
|
const suite = new benchmark_1.default.Suite()
|
|
72
71
|
.on('cycle', (event) => {
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
73
73
|
console.log(String(event.target));
|
|
74
74
|
// console.log(event.target)
|
|
75
75
|
})
|
|
@@ -83,7 +83,7 @@ async function runBenchOnce(opt, run) {
|
|
|
83
83
|
});
|
|
84
84
|
defer.resolve(results);
|
|
85
85
|
})
|
|
86
|
-
.on('error',
|
|
86
|
+
.on('error', (event) => {
|
|
87
87
|
console.log('bench error:\n', event.target.error);
|
|
88
88
|
});
|
|
89
89
|
const fnNames = Object.keys(opt.fns || {});
|
package/dist/cannon.model.d.ts
CHANGED
package/dist/cannon.profiles.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.expressWithMiddlewaresServerFactory = exports.bareExpressServerFactory = exports.bareNodeServerFactory = void 0;
|
|
4
|
+
exports.expressFunctionFactory = expressFunctionFactory;
|
|
5
|
+
exports.expressSyncFunctionFactory = expressSyncFunctionFactory;
|
|
4
6
|
const tslib_1 = require("tslib");
|
|
5
7
|
const node_http_1 = tslib_1.__importDefault(require("node:http"));
|
|
6
8
|
const bareNodeServerFactory = async () => {
|
|
7
|
-
return node_http_1.default.createServer((
|
|
9
|
+
return node_http_1.default.createServer((_req, res) => {
|
|
8
10
|
res.setHeader('content-type', 'application/json; charset=utf-8');
|
|
9
11
|
res.end(JSON.stringify({ hello: 'world' }));
|
|
10
12
|
});
|
|
@@ -14,7 +16,7 @@ const bareExpressServerFactory = async () => {
|
|
|
14
16
|
const app = require('express')();
|
|
15
17
|
app.disable('etag');
|
|
16
18
|
app.disable('x-powered-by');
|
|
17
|
-
app.get('/', (
|
|
19
|
+
app.get('/', (_req, res) => res.json({ hello: 'world' }));
|
|
18
20
|
return node_http_1.default.createServer(app);
|
|
19
21
|
};
|
|
20
22
|
exports.bareExpressServerFactory = bareExpressServerFactory;
|
|
@@ -33,7 +35,7 @@ const expressWithMiddlewaresServerFactory = async () => {
|
|
|
33
35
|
app.use(helmet.hsts());
|
|
34
36
|
app.use(helmet.ieNoOpen());
|
|
35
37
|
app.use(helmet.xssFilter());
|
|
36
|
-
app.get('/', (
|
|
38
|
+
app.get('/', (_req, res) => res.json({ hello: 'world' }));
|
|
37
39
|
return node_http_1.default.createServer(app);
|
|
38
40
|
};
|
|
39
41
|
exports.expressWithMiddlewaresServerFactory = expressWithMiddlewaresServerFactory;
|
|
@@ -45,18 +47,16 @@ function expressFunctionFactory(fn) {
|
|
|
45
47
|
const app = require('express')();
|
|
46
48
|
app.disable('etag');
|
|
47
49
|
app.disable('x-powered-by');
|
|
48
|
-
app.get('/', async (
|
|
50
|
+
app.get('/', async (_req, res) => res.json(await fn()));
|
|
49
51
|
return node_http_1.default.createServer(app);
|
|
50
52
|
};
|
|
51
53
|
}
|
|
52
|
-
exports.expressFunctionFactory = expressFunctionFactory;
|
|
53
54
|
function expressSyncFunctionFactory(fn) {
|
|
54
55
|
return async () => {
|
|
55
56
|
const app = require('express')();
|
|
56
57
|
app.disable('etag');
|
|
57
58
|
app.disable('x-powered-by');
|
|
58
|
-
app.get('/', (
|
|
59
|
+
app.get('/', (_req, res) => res.json(fn()));
|
|
59
60
|
return node_http_1.default.createServer(app);
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
|
-
exports.expressSyncFunctionFactory = expressSyncFunctionFactory;
|
package/dist/cannon.util.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.runCannonScript = runCannonScript;
|
|
4
|
+
exports.runCannon = runCannon;
|
|
4
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
6
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
6
7
|
/**
|
|
@@ -14,7 +15,6 @@ function runCannonScript(profiles, optInput = {}) {
|
|
|
14
15
|
clearTimeout(timeout);
|
|
15
16
|
});
|
|
16
17
|
}
|
|
17
|
-
exports.runCannonScript = runCannonScript;
|
|
18
18
|
async function runCannon(profiles, optInput = {}) {
|
|
19
19
|
const opt = {
|
|
20
20
|
name: 'Benchmark',
|
|
@@ -51,7 +51,7 @@ async function runCannon(profiles, optInput = {}) {
|
|
|
51
51
|
nodejs_lib_1.fs2.ensureDir(reportDirPath);
|
|
52
52
|
const resultByProfile = {};
|
|
53
53
|
const summaries = [];
|
|
54
|
-
for
|
|
54
|
+
for (const profileName of Object.keys(profiles)) {
|
|
55
55
|
resultByProfile[profileName] = await runCannonProfile(profileName, profiles[profileName], opt);
|
|
56
56
|
const summary = toSummary(profileName, resultByProfile[profileName]);
|
|
57
57
|
if (!opt.includeLatencyPercentiles) {
|
|
@@ -73,7 +73,6 @@ async function runCannon(profiles, optInput = {}) {
|
|
|
73
73
|
// }
|
|
74
74
|
return summaries;
|
|
75
75
|
}
|
|
76
|
-
exports.runCannon = runCannon;
|
|
77
76
|
async function runCannonProfile(profileName, serverFactory, opt) {
|
|
78
77
|
const { runs, connections, pipelining, duration, cooldown, host, renderProgressBar, renderResultsTable, renderLatencyTable, silent, } = opt;
|
|
79
78
|
const autocannon = require('autocannon');
|
|
@@ -82,7 +81,7 @@ async function runCannonProfile(profileName, serverFactory, opt) {
|
|
|
82
81
|
const { port } = server.address();
|
|
83
82
|
const url = `${host}:${port}${opt.path}`;
|
|
84
83
|
let finalResult = undefined;
|
|
85
|
-
for
|
|
84
|
+
for (const run of (0, js_lib_1._range)(1, runs + 1)) {
|
|
86
85
|
console.log(`\n${(0, nodejs_lib_1.boldRed)('=== ' + profileName + ' ===')} run ${(0, nodejs_lib_1.yellow)(run)}/${(0, nodejs_lib_1.yellow)(runs)}\n`);
|
|
87
86
|
const doneDefer = (0, js_lib_1.pDefer)();
|
|
88
87
|
const instance = autocannon({
|
|
@@ -9,7 +9,8 @@ Adapted for typescript.
|
|
|
9
9
|
Super-experimental!
|
|
10
10
|
*/
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.asciiColor = void 0;
|
|
13
|
+
exports.asciiPlot = asciiPlot;
|
|
13
14
|
/* eslint-disable */
|
|
14
15
|
exports.asciiColor = {
|
|
15
16
|
black: '\u001B[30m',
|
|
@@ -66,13 +67,11 @@ function asciiPlot(seriesInput, cfg = {}) {
|
|
|
66
67
|
for (const element of series) {
|
|
67
68
|
width = Math.max(width, element.length);
|
|
68
69
|
}
|
|
69
|
-
width
|
|
70
|
+
width += offset;
|
|
70
71
|
const symbols = typeof cfg.symbols !== 'undefined' ? cfg.symbols : defaultSymbols;
|
|
71
72
|
const format = typeof cfg.format !== 'undefined'
|
|
72
73
|
? cfg.format
|
|
73
|
-
:
|
|
74
|
-
return (padding + x.toFixed(2)).slice(-padding.length);
|
|
75
|
-
};
|
|
74
|
+
: (x) => (padding + x.toFixed(2)).slice(-padding.length);
|
|
76
75
|
const result = new Array(rows + 1); // empty space
|
|
77
76
|
for (let i = 0; i <= rows; i++) {
|
|
78
77
|
result[i] = new Array(width);
|
|
@@ -84,7 +83,7 @@ function asciiPlot(seriesInput, cfg = {}) {
|
|
|
84
83
|
// axis + labels
|
|
85
84
|
const label = format(rows > 0 ? max - ((y - min2) * range) / rows : y, y - min2);
|
|
86
85
|
result[y - min2][Math.max(offset - label.length, 0)] = label;
|
|
87
|
-
result[y - min2][offset - 1] = y
|
|
86
|
+
result[y - min2][offset - 1] = y === 0 ? symbols[0] : symbols[1];
|
|
88
87
|
}
|
|
89
88
|
for (const [j, element] of series.entries()) {
|
|
90
89
|
const currentColor = colors[j % colors.length];
|
|
@@ -94,7 +93,7 @@ function asciiPlot(seriesInput, cfg = {}) {
|
|
|
94
93
|
// plot the line
|
|
95
94
|
const y0 = Math.round(element[x + 0] * ratio) - min2;
|
|
96
95
|
const y1 = Math.round(element[x + 1] * ratio) - min2;
|
|
97
|
-
if (y0
|
|
96
|
+
if (y0 === y1) {
|
|
98
97
|
result[rows - y0][x + offset] = colored(symbols[4], currentColor);
|
|
99
98
|
}
|
|
100
99
|
else {
|
|
@@ -108,10 +107,5 @@ function asciiPlot(seriesInput, cfg = {}) {
|
|
|
108
107
|
}
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
|
-
return result
|
|
112
|
-
.map(function (x) {
|
|
113
|
-
return x.join('');
|
|
114
|
-
})
|
|
115
|
-
.join('\n');
|
|
110
|
+
return result.map(x => x.join('')).join('\n');
|
|
116
111
|
}
|
|
117
|
-
exports.asciiPlot = asciiPlot;
|
package/package.json
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/bench-lib",
|
|
3
3
|
"scripts": {
|
|
4
|
-
"prepare": "husky"
|
|
4
|
+
"prepare": "husky",
|
|
5
|
+
"build": "dev-lib build",
|
|
6
|
+
"test": "dev-lib test",
|
|
7
|
+
"lint": "dev-lib lint",
|
|
8
|
+
"bt": "dev-lib bt",
|
|
9
|
+
"lbt": "dev-lib lbt"
|
|
5
10
|
},
|
|
6
11
|
"dependencies": {
|
|
7
|
-
"@naturalcycles/js-lib": "^14
|
|
8
|
-
"@naturalcycles/nodejs-lib": "^13
|
|
9
|
-
"autocannon": "^
|
|
10
|
-
"benchmark": "^2
|
|
12
|
+
"@naturalcycles/js-lib": "^14",
|
|
13
|
+
"@naturalcycles/nodejs-lib": "^13",
|
|
14
|
+
"autocannon": "^8",
|
|
15
|
+
"benchmark": "^2"
|
|
11
16
|
},
|
|
12
17
|
"devDependencies": {
|
|
13
|
-
"@naturalcycles/dev-lib": "^
|
|
14
|
-
"@types/benchmark": "^2
|
|
15
|
-
"@types/express": "^
|
|
16
|
-
"@types/node": "^
|
|
17
|
-
"express": "^4
|
|
18
|
-
"fastify": "^
|
|
19
|
-
"helmet": "^
|
|
20
|
-
"jest": "^29
|
|
18
|
+
"@naturalcycles/dev-lib": "^15",
|
|
19
|
+
"@types/benchmark": "^2",
|
|
20
|
+
"@types/express": "^5",
|
|
21
|
+
"@types/node": "^22",
|
|
22
|
+
"express": "^4",
|
|
23
|
+
"fastify": "^5",
|
|
24
|
+
"helmet": "^8",
|
|
25
|
+
"jest": "^29"
|
|
21
26
|
},
|
|
22
27
|
"files": [
|
|
23
28
|
"dist"
|
|
@@ -32,9 +37,9 @@
|
|
|
32
37
|
"url": "https://github.com/NaturalCycles/bench-lib"
|
|
33
38
|
},
|
|
34
39
|
"engines": {
|
|
35
|
-
"node": ">=
|
|
40
|
+
"node": ">=22.10.0"
|
|
36
41
|
},
|
|
37
|
-
"version": "3.
|
|
42
|
+
"version": "3.1.1",
|
|
38
43
|
"description": "Benchmarking library, based on Benchmark.js and Autocannon",
|
|
39
44
|
"author": "Natural Cycles Team",
|
|
40
45
|
"license": "MIT"
|