Skip to content

Commit 7202f35

Browse files
committed
hdr-histogram-js
1 parent b6cb1b1 commit 7202f35

File tree

5 files changed

+73
-46
lines changed

5 files changed

+73
-46
lines changed

Diff for: benchmark/lib/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ async function getName() {
3131
.parseSync().name;
3232
}
3333

34-
3534
const runnerPath = fileURLToPath(new URL('runner.js', import.meta.url)),
3635
path = new URL(`${await getName()}/`, import.meta.url),
3736
metadata = await import(new URL('index.js', path));

Diff for: benchmark/lib/runner.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import yargs from 'yargs';
22
import { hideBin } from 'yargs/helpers';
33
import { basename } from 'path';
4+
import * as hdr from 'hdr-histogram-js';
5+
hdr.initWebAssemblySync();
46

57
const { path, times, concurrency } = yargs(hideBin(process.argv))
68
.option('path', {
@@ -39,26 +41,31 @@ const [ { benchmark, teardown }, metadata ] = await Promise.all([
3941

4042
async function run(times) {
4143
return new Promise(resolve => {
44+
const histogram = hdr.build({ useWebAssembly: true });
4245
let num = 0,
4346
inProgress = 0;
4447

4548
function run() {
4649
++inProgress;
4750
++num;
51+
52+
const start = process.hrtime.bigint();
4853
benchmark(metadata)
4954
.catch(err => console.error(err))
5055
.finally(() => {
56+
histogram.recordValue(Number(process.hrtime.bigint() - start));
5157
--inProgress;
5258

5359
if (num < times) {
5460
run();
5561
} else if (inProgress === 0) {
56-
resolve();
62+
resolve(histogram);
5763
}
5864
});
5965
}
6066

61-
for (let i = 0; i < concurrency; i++) {
67+
const toInitiate = Math.min(concurrency, times);
68+
for (let i = 0; i < toInitiate; i++) {
6269
run();
6370
}
6471
});
@@ -68,9 +75,8 @@ async function run(times) {
6875
await run(Math.min(times * 0.1, 10_000));
6976

7077
// benchmark
71-
const start = process.hrtime.bigint();
72-
await run(times);
73-
const took = (process.hrtime.bigint() - start);
74-
console.log(`[${basename(path)}]: took ${took / 1_000_000n}ms, ${took / BigInt(times)}ns per operation`);
78+
const histogram = await run(times);
79+
console.log(`[${basename(path)}]:`);
80+
console.table(histogram.toJSON());
7581

7682
await teardown();

Diff for: benchmark/package-lock.json

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

Diff for: benchmark/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dependencies": {
1010
"@node-redis/client-local": "../packages/client",
1111
"@node-redis/client-production": "npm:@node-redis/[email protected]",
12-
"hazelcast-client": "^5.0.2",
12+
"hdr-histogram-js": "2.0.1",
1313
"ioredis": "4.28.1",
1414
"redis-v3": "npm:[email protected]",
1515
"yargs": "17.3.0"

Diff for: benchmark/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
redisbench_admin>=0.5.24

0 commit comments

Comments
 (0)