Skip to content

Commit a9eb06e

Browse files
committed
chore(deps): bump to tinybench 6.0.0
Signed-off-by: Jérôme Benoit <[email protected]>
1 parent 33f363d commit a9eb06e

File tree

4 files changed

+110
-76
lines changed

4 files changed

+110
-76
lines changed

benchmarks/benchmarks-utils.mjs

Lines changed: 82 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -70,31 +70,34 @@ const buildPoolifierBenchmarkDenoBench = (
7070
} and ${enableTasksQueue ? 'with' : 'without'} tasks queue`,
7171
{ group: `${name}` },
7272
async (b) => {
73-
const pool = buildPoolifierPool(
74-
workerType,
75-
poolType,
76-
poolSize,
77-
poolOptions,
78-
)
79-
if (workerChoiceStrategy != null) {
80-
strictEqual(pool.opts.workerChoiceStrategy, workerChoiceStrategy)
81-
}
82-
if (enableTasksQueue != null) {
83-
strictEqual(pool.opts.enableTasksQueue, enableTasksQueue)
84-
}
85-
if (measurement != null) {
86-
strictEqual(
87-
pool.opts.workerChoiceStrategyOptions.measurement,
88-
measurement,
89-
)
73+
let pool
74+
try {
75+
pool = buildPoolifierPool(workerType, poolType, poolSize, poolOptions)
76+
if (workerChoiceStrategy != null) {
77+
strictEqual(pool.opts.workerChoiceStrategy, workerChoiceStrategy)
78+
}
79+
if (enableTasksQueue != null) {
80+
strictEqual(pool.opts.enableTasksQueue, enableTasksQueue)
81+
}
82+
if (measurement != null) {
83+
strictEqual(
84+
pool.opts.workerChoiceStrategyOptions.measurement,
85+
measurement,
86+
)
87+
}
88+
b.start()
89+
await runPoolifierPool(pool, {
90+
taskExecutions,
91+
workerData,
92+
})
93+
b.end()
94+
} catch (error) {
95+
console.error(error)
96+
} finally {
97+
if (pool != null) {
98+
await pool.destroy()
99+
}
90100
}
91-
b.start()
92-
await runPoolifierPool(pool, {
93-
taskExecutions,
94-
workerData,
95-
})
96-
b.end()
97-
await pool.destroy()
98101
},
99102
)
100103
}
@@ -250,16 +253,47 @@ export const runtime = (() => {
250253
throw new Error('Unsupported JavaScript runtime environment')
251254
})()
252255

256+
export const envGet = (key) => {
257+
return {
258+
browser: () => undefined,
259+
deno: () => Deno?.env?.get?.(key),
260+
bun: () => Bun?.env?.[key],
261+
}[runtime]()
262+
}
263+
264+
export const writeFile = (filePath, content) => {
265+
return {
266+
browser: () => {
267+
throw new Error('File writing is not supported in browser runtime')
268+
},
269+
deno: () => Deno.writeTextFileSync(filePath, content),
270+
bun: async () => await Bun.write(filePath, content),
271+
}[runtime]()
272+
}
273+
274+
export const exit = (code = 0) => {
275+
return {
276+
browser: () => {
277+
throw new Error('Process exit is not supported in browser runtime')
278+
},
279+
deno: () => Deno.exit(code),
280+
// deno-lint-ignore no-process-global
281+
bun: () => process.exit(code),
282+
}[runtime]()
283+
}
284+
253285
export const runPoolifierBenchmarkTinyBench = async (
254286
name,
255287
workerType,
256288
poolType,
257289
poolSize,
258290
{ taskExecutions, workerData },
259291
) => {
292+
const bmfResults = {}
293+
let pool
260294
try {
261295
const bench = new Bench()
262-
const pool = buildPoolifierPool(workerType, poolType, poolSize)
296+
pool = buildPoolifierPool(workerType, poolType, poolSize)
263297

264298
for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) {
265299
for (const enableTasksQueue of [false, true]) {
@@ -328,25 +362,35 @@ export const runPoolifierBenchmarkTinyBench = async (
328362

329363
const tasks = await bench.run()
330364
console.table(bench.table())
331-
await pool.destroy()
332365

333-
const bmfResults = {}
334366
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-
},
367+
if (
368+
task.result?.state === 'completed' ||
369+
task.result?.state === 'aborted-with-statistics'
370+
) {
371+
bmfResults[task.name] = {
372+
latency: {
373+
value: task.result.latency.mean,
374+
lower_value: task.result.latency.mean - task.result.latency.sd,
375+
upper_value: task.result.latency.mean + task.result.latency.sd,
376+
},
377+
throughput: {
378+
value: task.result.throughput.mean,
379+
lower_value: task.result.throughput.mean -
380+
task.result.throughput.sd,
381+
upper_value: task.result.throughput.mean +
382+
task.result.throughput.sd,
383+
},
384+
}
346385
}
347386
}
348387
return bmfResults
349388
} catch (error) {
350389
console.error(error)
390+
return bmfResults
391+
} finally {
392+
if (pool != null) {
393+
await pool.destroy()
394+
}
351395
}
352396
}

benchmarks/internal/bench.mjs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { availableParallelism, PoolTypes, WorkerTypes } from '../../src/mod.ts'
22
import { TaskFunctions } from '../benchmarks-types.mjs'
33
import {
4+
envGet,
5+
exit,
46
runPoolifierBenchmarkDenoBench,
57
runPoolifierBenchmarkTinyBench,
68
runtime,
9+
writeFile,
710
} from '../benchmarks-utils.mjs'
811

912
const poolSize = availableParallelism()
@@ -13,9 +16,10 @@ const workerData = {
1316
taskSize: 1000,
1417
}
1518
const benchmarkReportFile = 'benchmark-report.json'
16-
let benchmarkReport
1719

1820
const runBenchmark = async () => {
21+
let benchmarkReport = {}
22+
1923
const fixedThreadPoolGroupname = `FixedThreadPool on ${runtime}`
2024
const dynamicThreadPoolGroupname = `DynamicThreadPool on ${runtime}`
2125
return await {
@@ -49,11 +53,6 @@ const runBenchmark = async () => {
4953
},
5054
)),
5155
}
52-
Deno.env.get('CI') != null &&
53-
Deno.writeTextFileSync(
54-
benchmarkReportFile,
55-
JSON.stringify(benchmarkReport),
56-
)
5756
break
5857
default:
5958
runPoolifierBenchmarkDenoBench(
@@ -78,6 +77,7 @@ const runBenchmark = async () => {
7877
)
7978
break
8079
}
80+
return benchmarkReport
8181
},
8282
bun: async () => {
8383
const { parseArgs } = await import('util')
@@ -119,15 +119,19 @@ const runBenchmark = async () => {
119119
},
120120
)),
121121
}
122-
Bun.env.CI != null &&
123-
(await Bun.write(
124-
benchmarkReportFile,
125-
JSON.stringify(benchmarkReport),
126-
))
127122
break
128123
}
124+
return benchmarkReport
129125
},
130126
}[runtime]()
131127
}
132128

133-
await runBenchmark()
129+
try {
130+
const benchmarkReport = await runBenchmark()
131+
if (envGet('CI') != null) {
132+
await writeFile(benchmarkReportFile, JSON.stringify(benchmarkReport))
133+
}
134+
} catch (error) {
135+
console.error(error)
136+
exit(1)
137+
}

deno.json

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
"version": "0.5.15",
44
"exports": "./src/mod.ts",
55
"compilerOptions": {
6-
"lib": [
7-
"deno.worker"
8-
],
6+
"lib": ["deno.worker"],
97
"strict": true
108
},
119
"tasks": {
@@ -27,33 +25,21 @@
2725
"documentation": "deno doc ./src/mod.ts"
2826
},
2927
"test": {
30-
"include": [
31-
"./tests/**/*.test.mjs"
32-
]
28+
"include": ["./tests/**/*.test.mjs"]
3329
},
3430
"fmt": {
3531
"semiColons": false,
3632
"singleQuote": true
3733
},
3834
"imports": {
39-
"tinybench": "npm:tinybench@^5.1.0",
35+
"tinybench": "npm:tinybench@^6.0.0",
4036
"@std/cli": "jsr:@std/cli@^1.0.23",
4137
"@std/expect": "jsr:@std/expect@^1.0.17",
4238
"@std/testing": "jsr:@std/testing@^1.0.16"
4339
},
4440
"publish": {
45-
"include": [
46-
"LICENSE",
47-
"README.md",
48-
"deno.json",
49-
"src/**/*.ts"
50-
]
41+
"include": ["LICENSE", "README.md", "deno.json", "src/**/*.ts"]
5142
},
52-
"exclude": [
53-
"./coverage",
54-
"./dist/browser",
55-
"./dist/esm",
56-
"./npm"
57-
],
43+
"exclude": ["./coverage", "./dist/browser", "./dist/esm", "./npm"],
5844
"lock": false
5945
}

tests/pools/selection-strategies/selection-strategies.test.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ describe('Selection strategies test suite', () => {
296296
it({
297297
name: 'Verify ROUND_ROBIN strategy can be run in a dynamic pool',
298298
ignore: Deno.build.os === 'linux' &&
299-
parseInt(Deno.version.deno.split('.')[0]) >= 2,
299+
Number.parseInt(Deno.version.deno.split('.')[0]) >= 2,
300300
fn: async () => {
301301
const workerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN
302302
const pool = new DynamicThreadPool(
@@ -568,7 +568,7 @@ describe('Selection strategies test suite', () => {
568568
it({
569569
name: 'Verify LEAST_USED strategy can be run in a dynamic pool',
570570
ignore: Deno.build.os === 'linux' &&
571-
parseInt(Deno.version.deno.split('.')[0]) >= 2,
571+
Number.parseInt(Deno.version.deno.split('.')[0]) >= 2,
572572
fn: async () => {
573573
const pool = new DynamicThreadPool(
574574
min,
@@ -1269,7 +1269,7 @@ describe('Selection strategies test suite', () => {
12691269
it({
12701270
name: 'Verify FAIR_SHARE strategy can be run in a dynamic pool',
12711271
ignore: Deno.build.os === 'linux' &&
1272-
parseInt(Deno.version.deno.split('.')[0]) >= 2,
1272+
Number.parseInt(Deno.version.deno.split('.')[0]) >= 2,
12731273
fn: async () => {
12741274
const pool = new DynamicThreadPool(
12751275
min,
@@ -1373,7 +1373,7 @@ describe('Selection strategies test suite', () => {
13731373
name:
13741374
'Verify FAIR_SHARE strategy can be run in a dynamic pool with median runtime statistic',
13751375
ignore: Deno.build.os === 'linux' &&
1376-
parseInt(Deno.version.deno.split('.')[0]) >= 2,
1376+
Number.parseInt(Deno.version.deno.split('.')[0]) >= 2,
13771377
fn: async () => {
13781378
const pool = new DynamicThreadPool(
13791379
min,
@@ -1680,7 +1680,7 @@ describe('Selection strategies test suite', () => {
16801680
it({
16811681
name: 'Verify WEIGHTED_ROUND_ROBIN strategy can be run in a dynamic pool',
16821682
ignore: Deno.build.os === 'linux' &&
1683-
parseInt(Deno.version.deno.split('.')[0]) >= 2,
1683+
Number.parseInt(Deno.version.deno.split('.')[0]) >= 2,
16841684
fn: async () => {
16851685
const pool = new DynamicThreadPool(
16861686
min,
@@ -1770,7 +1770,7 @@ describe('Selection strategies test suite', () => {
17701770
name:
17711771
'Verify WEIGHTED_ROUND_ROBIN strategy can be run in a dynamic pool with median runtime statistic',
17721772
ignore: Deno.build.os === 'linux' &&
1773-
parseInt(Deno.version.deno.split('.')[0]) >= 2,
1773+
Number.parseInt(Deno.version.deno.split('.')[0]) >= 2,
17741774
fn: async () => {
17751775
const pool = new DynamicThreadPool(
17761776
min,
@@ -2120,7 +2120,7 @@ describe('Selection strategies test suite', () => {
21202120
name:
21212121
'Verify INTERLEAVED_WEIGHTED_ROUND_ROBIN strategy can be run in a dynamic pool',
21222122
ignore: Deno.build.os === 'linux' &&
2123-
parseInt(Deno.version.deno.split('.')[0]) >= 2,
2123+
Number.parseInt(Deno.version.deno.split('.')[0]) >= 2,
21242124
fn: async () => {
21252125
const pool = new DynamicThreadPool(
21262126
min,

0 commit comments

Comments
 (0)