Skip to content

Commit 6ffb0c7

Browse files
committed
refactor: switch benchmarks to tinybench
Signed-off-by: Jérôme Benoit <[email protected]>
1 parent 55e3338 commit 6ffb0c7

File tree

7 files changed

+122
-106
lines changed

7 files changed

+122
-106
lines changed

.github/workflows/internal-benchmark.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ jobs:
4343
--file benchmark-report.json \
4444
--err \
4545
--github-actions ${{ secrets.GITHUB_TOKEN }} \
46-
"deno task benchmark:tatami-ng"
46+
"deno task benchmark:tinybench"

.serena/memories/suggested_commands.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Development Commands
44

5-
- `deno task test` - Run all tests
5+
- `deno task test` - Run tests
66
- `deno task test:parallel` - Run tests in parallel
77
- `deno task test:coverage` - Run tests with coverage
88
- `deno test -A tests/path/to/specific.test.mjs` - Run single test file
@@ -16,8 +16,9 @@
1616
## Benchmarking Commands
1717

1818
- `deno task benchmark:deno` - Run Deno benchmarks
19-
- `deno task benchmark:tatami-ng` - Run Tatami-ng benchmarks
20-
- `deno task benchmark:tatami-ng:debug` - Run benchmarks with debugging
19+
- `deno task benchmark:tinybench` - Run Tinybench benchmarks
20+
- `deno task benchmark:tinybench:debug` - Run Tinybench benchmarks with
21+
debugging
2122

2223
## Documentation
2324

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
{
1818
"type": "node",
1919
"request": "launch",
20-
"name": "Launch Tatami NG Benchmark Debug",
20+
"name": "Launch Tinybench Benchmark Debug",
2121
"cwd": "${workspaceFolder}",
2222
"runtimeExecutable": "deno",
23-
"runtimeArgs": ["task", "benchmark:tatami-ng:debug"],
23+
"runtimeArgs": ["task", "benchmark:tinybench:debug"],
2424
"skipFiles": ["<node_internals>/**"],
2525
"stopOnEntry": true
2626
}

benchmarks/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ poolifier cloned repository and run:
3030

3131
#### Deno
3232

33-
- `deno task benchmark:tatami-ng` or
33+
- `deno task benchmark:tinybench` or
3434
- `deno task benchmark:deno`
3535

3636
#### Bun
3737

38-
- `bun ./benchmarks/internal/bench.mjs -t tatami-ng`
38+
- `bun ./benchmarks/internal/bench.mjs -t tinybench`
3939

4040
### [Results](https://bencher.dev/perf/poolifier-web-worker)

benchmarks/benchmarks-utils.mjs

Lines changed: 102 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
rmSync,
88
writeFileSync,
99
} from 'node:fs'
10-
import { bench, group, run } from '@poolifier/tatami-ng'
10+
import { Bench } from 'tinybench'
1111
import {
1212
DynamicThreadPool,
1313
FixedThreadPool,
@@ -144,87 +144,6 @@ export const runPoolifierBenchmarkDenoBench = (
144144
}
145145
}
146146

147-
export const runPoolifierBenchmarkTatamiNg = async (
148-
name,
149-
workerType,
150-
poolType,
151-
poolSize,
152-
benchmarkReporter,
153-
{ taskExecutions, workerData },
154-
) => {
155-
try {
156-
const pool = buildPoolifierPool(workerType, poolType, poolSize)
157-
for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) {
158-
for (const enableTasksQueue of [false, true]) {
159-
if (workerChoiceStrategy === WorkerChoiceStrategies.FAIR_SHARE) {
160-
for (const measurement of [Measurements.runTime]) {
161-
group(name, () => {
162-
bench(
163-
`${name} with ${workerChoiceStrategy}, with ${measurement} and ${
164-
enableTasksQueue ? 'with' : 'without'
165-
} tasks queue`,
166-
async () => {
167-
await runPoolifierPool(pool, {
168-
taskExecutions,
169-
workerData,
170-
})
171-
},
172-
{
173-
before: () => {
174-
pool.setWorkerChoiceStrategy(workerChoiceStrategy, {
175-
measurement,
176-
})
177-
pool.enableTasksQueue(enableTasksQueue)
178-
strictEqual(
179-
pool.opts.workerChoiceStrategy,
180-
workerChoiceStrategy,
181-
)
182-
strictEqual(pool.opts.enableTasksQueue, enableTasksQueue)
183-
strictEqual(
184-
pool.opts.workerChoiceStrategyOptions.measurement,
185-
measurement,
186-
)
187-
},
188-
},
189-
)
190-
})
191-
}
192-
} else {
193-
group(name, () => {
194-
bench(
195-
`${name} with ${workerChoiceStrategy} and ${
196-
enableTasksQueue ? 'with' : 'without'
197-
} tasks queue`,
198-
async () => {
199-
await runPoolifierPool(pool, {
200-
taskExecutions,
201-
workerData,
202-
})
203-
},
204-
{
205-
before: () => {
206-
pool.setWorkerChoiceStrategy(workerChoiceStrategy)
207-
pool.enableTasksQueue(enableTasksQueue)
208-
strictEqual(
209-
pool.opts.workerChoiceStrategy,
210-
workerChoiceStrategy,
211-
)
212-
strictEqual(pool.opts.enableTasksQueue, enableTasksQueue)
213-
},
214-
},
215-
)
216-
})
217-
}
218-
}
219-
}
220-
const report = await run({ reporter: benchmarkReporter })
221-
await pool.destroy()
222-
return report
223-
} catch (error) {
224-
console.error(error)
225-
}
226-
}
227-
228147
const jsonIntegerSerialization = (n) => {
229148
for (let i = 0; i < n; i++) {
230149
const o = {
@@ -330,3 +249,104 @@ export const runtime = (() => {
330249
if (isBrowser) return JSRuntime.browser
331250
throw new Error('Unsupported JavaScript runtime environment')
332251
})()
252+
253+
export const runPoolifierBenchmarkTinyBench = async (
254+
name,
255+
workerType,
256+
poolType,
257+
poolSize,
258+
{ taskExecutions, workerData },
259+
) => {
260+
try {
261+
const bench = new Bench()
262+
const pool = buildPoolifierPool(workerType, poolType, poolSize)
263+
264+
for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) {
265+
for (const enableTasksQueue of [false, true]) {
266+
if (workerChoiceStrategy === WorkerChoiceStrategies.FAIR_SHARE) {
267+
for (const measurement of [Measurements.runTime]) {
268+
const taskName =
269+
`${name} with ${workerChoiceStrategy}, with ${measurement} and ${
270+
enableTasksQueue ? 'with' : 'without'
271+
} tasks queue`
272+
273+
bench.add(
274+
taskName,
275+
async () => {
276+
await runPoolifierPool(pool, {
277+
taskExecutions,
278+
workerData,
279+
})
280+
},
281+
{
282+
beforeAll: () => {
283+
pool.setWorkerChoiceStrategy(workerChoiceStrategy, {
284+
measurement,
285+
})
286+
pool.enableTasksQueue(enableTasksQueue)
287+
strictEqual(
288+
pool.opts.workerChoiceStrategy,
289+
workerChoiceStrategy,
290+
)
291+
strictEqual(pool.opts.enableTasksQueue, enableTasksQueue)
292+
strictEqual(
293+
pool.opts.workerChoiceStrategyOptions.measurement,
294+
measurement,
295+
)
296+
},
297+
},
298+
)
299+
}
300+
} else {
301+
const taskName = `${name} with ${workerChoiceStrategy} and ${
302+
enableTasksQueue ? 'with' : 'without'
303+
} tasks queue`
304+
305+
bench.add(
306+
taskName,
307+
async () => {
308+
await runPoolifierPool(pool, {
309+
taskExecutions,
310+
workerData,
311+
})
312+
},
313+
{
314+
beforeAll: () => {
315+
pool.setWorkerChoiceStrategy(workerChoiceStrategy)
316+
pool.enableTasksQueue(enableTasksQueue)
317+
strictEqual(
318+
pool.opts.workerChoiceStrategy,
319+
workerChoiceStrategy,
320+
)
321+
strictEqual(pool.opts.enableTasksQueue, enableTasksQueue)
322+
},
323+
},
324+
)
325+
}
326+
}
327+
}
328+
329+
const tasks = await bench.run()
330+
console.table(bench.table())
331+
await pool.destroy()
332+
333+
const bmfResults = {}
334+
for (const task of tasks) {
335+
bmfResults[task.name] = {
336+
latency: {
337+
value: task.result.latency.mean,
338+
lower_value: task.result.latency.mean - task.result.latency.sd,
339+
upper_value: task.result.latency.mean + task.result.latency.sd,
340+
},
341+
throughput: {
342+
value: task.result.throughput.mean,
343+
lower_value: task.result.throughput.mean - task.result.throughput.sd,
344+
upper_value: task.result.throughput.mean + task.result.throughput.sd,
345+
},
346+
}
347+
}
348+
return bmfResults
349+
} catch (error) {
350+
console.error(error)
351+
}
352+
}

benchmarks/internal/bench.mjs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { bmf } from '@poolifier/tatami-ng'
21
import { availableParallelism, PoolTypes, WorkerTypes } from '../../src/mod.ts'
32
import { TaskFunctions } from '../benchmarks-types.mjs'
43
import {
54
runPoolifierBenchmarkDenoBench,
6-
runPoolifierBenchmarkTatamiNg,
5+
runPoolifierBenchmarkTinyBench,
76
runtime,
87
} from '../benchmarks-utils.mjs'
98

@@ -26,26 +25,24 @@ const runBenchmark = async () => {
2625
deno: async () => {
2726
const { parseArgs } = await import('@std/cli/parse-args')
2827
switch (parseArgs(Deno.args).t) {
29-
case 'tatami-ng':
30-
benchmarkReport = await runPoolifierBenchmarkTatamiNg(
28+
case 'tinybench':
29+
benchmarkReport = await runPoolifierBenchmarkTinyBench(
3130
fixedThreadPoolGroupname,
3231
WorkerTypes.web,
3332
PoolTypes.fixed,
3433
poolSize,
35-
bmf,
3634
{
3735
taskExecutions,
3836
workerData,
3937
},
4038
)
4139
benchmarkReport = {
4240
...benchmarkReport,
43-
...(await runPoolifierBenchmarkTatamiNg(
41+
...(await runPoolifierBenchmarkTinyBench(
4442
dynamicThreadPoolGroupname,
4543
WorkerTypes.web,
4644
PoolTypes.dynamic,
4745
poolSize,
48-
bmf,
4946
{
5047
taskExecutions,
5148
workerData,
@@ -97,27 +94,25 @@ const runBenchmark = async () => {
9794
allowPositionals: true,
9895
}).values.type
9996
) {
100-
case 'tatami-ng':
97+
case 'tinybench':
10198
default:
102-
benchmarkReport = await runPoolifierBenchmarkTatamiNg(
99+
benchmarkReport = await runPoolifierBenchmarkTinyBench(
103100
fixedThreadPoolGroupname,
104101
WorkerTypes.web,
105102
PoolTypes.fixed,
106103
poolSize,
107-
bmf,
108104
{
109105
taskExecutions,
110106
workerData,
111107
},
112108
)
113109
benchmarkReport = {
114110
...benchmarkReport,
115-
...(await runPoolifierBenchmarkTatamiNg(
111+
...(await runPoolifierBenchmarkTinyBench(
116112
dynamicThreadPoolGroupname,
117113
WorkerTypes.web,
118114
PoolTypes.dynamic,
119115
poolSize,
120-
bmf,
121116
{
122117
taskExecutions,
123118
workerData,

deno.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"tasks": {
1010
"benchmark:deno": "deno bench -A ./benchmarks/internal/bench.mjs",
1111
"benchmark:deno:json": "deno bench -A --json ./benchmarks/internal/bench.mjs",
12-
"benchmark:tatami-ng": "deno run -A ./benchmarks/internal/bench.mjs -t tatami-ng",
13-
"benchmark:tatami-ng:debug": "deno run -A --inspect ./benchmarks/internal/bench.mjs -t tatami-ng",
12+
"benchmark:tinybench": "deno run -A ./benchmarks/internal/bench.mjs -t tinybench",
13+
"benchmark:tinybench:debug": "deno run -A --inspect ./benchmarks/internal/bench.mjs -t tinybench",
1414
"bundle": "deno run -A bundle.ts",
1515
"test": "ENVIRONMENT=test deno test -A",
1616
"test:parallel": "ENVIRONMENT=test deno test -A --parallel",
@@ -32,8 +32,8 @@
3232
"singleQuote": true
3333
},
3434
"imports": {
35-
"@poolifier/tatami-ng": "jsr:@poolifier/tatami-ng@^0.8.18",
36-
"@std/cli": "jsr:@std/cli@^1.0.22",
35+
"tinybench": "npm:tinybench@^5.1.0",
36+
"@std/cli": "jsr:@std/cli@^1.0.23",
3737
"@std/expect": "jsr:@std/expect@^1.0.17",
3838
"@std/testing": "jsr:@std/testing@^1.0.15"
3939
},

0 commit comments

Comments
 (0)