-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.mjs
40 lines (32 loc) · 1.05 KB
/
benchmark.mjs
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
#!/usr/bin/env node
import { Suite } from '@jonahsnider/benchmark';
import { Background, withCancel, withTimeout } from './dist/context.mjs';
const suite = new Suite('simple', {
warmup: { trials: 1_000_000 },
run: { trials: 100_000 },
});
suite.addTest('Lifecycle', async () => {
var { cancel, ctx } = withCancel(Background());
var ctx = ctx.withValue('hello', 'world');
var { ctx } = withTimeout(ctx, 1000);
const value = ctx.getValue('hello');
cancel();
// const reason = await ctx.done();
});
const results = await suite.run();
const table = [...results]
// Convert median execution time to mean ops/sec
.map(([library, histogram]) => [
library,
Math.round(1e9 / histogram.percentile(50)),
Math.round(1e9 / histogram.percentile(99)),
])
// Sort fastest to slowest
.sort(([, a], [, b]) => b - a)
// Convert to object for console.table
.map(([library, p50OpsPerSec, p99OpsPerSec]) => ({
library,
'p50 ops/sec': p50OpsPerSec.toLocaleString(),
'p99 ops/sec': p99OpsPerSec.toLocaleString(),
}));
console.table(table);