Skip to content

Commit 77f7a7b

Browse files
committed
Add latency value to benchmark reporting
1 parent 5516471 commit 77f7a7b

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

bench/index.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
11
const { Suite, jsonReport } = require("bench-node");
22
const addon = require("./index.node");
33

4+
function median(values) {
5+
const sorted = [...values].sort((a, b) => a - b);
6+
const n = sorted.length;
7+
return n % 2 === 0
8+
? (sorted[n / 2 - 1] + sorted[n / 2]) / 2
9+
: sorted[Math.floor(n / 2)];
10+
}
11+
412
// A custom reporter for the bencher.dev benchmarking platform.
513
// Format: https://bencher.dev/docs/reference/bencher-metric-format/
14+
//
15+
// The reporter provides two measures for each benchmark:
16+
// - "throughput": The number of operations per second.
17+
// - "latency": The time taken to perform an operation, in ns.
18+
// * "value": The median value of all samples.
19+
// * "lower_value": The minimum value of all samples.
20+
// * "upper_value": The maximum value of all samples.
621
function reportBencherDev(results) {
722
const bmf = Object.create(null);
823
for (const result of results) {
9-
// If https://github.com/RafaelGSS/bench-node/issues/66 is fixed, then we can use
10-
// result.histogram to report a "latency" measure with the median as the "value",
11-
// min as "lower_value", and max as "upper_value".
1224
bmf[result.name] = {
1325
throughput: {
1426
value: result.opsSec,
1527
},
28+
latency: {
29+
value: median(result.histogram.sampleData),
30+
lower_value: result.histogram.min,
31+
upper_value: result.histogram.max,
32+
},
1633
};
1734
}
1835
console.log(JSON.stringify(bmf, null, 2));

bench/package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bench/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
},
2323
"homepage": "https://github.com/neon-bindings/neon#readme",
2424
"dependencies": {
25-
"bench-node": "^0.5.3"
25+
"bench-node": "^0.5.4"
2626
}
2727
}

0 commit comments

Comments
 (0)