fix: fix continuous benchmarking
[poolifier.git] / benchmarks / internal / bench.mjs
1 import assert from 'node:assert'
2 import Benchmark from 'benchmark'
3 import {
4 PoolTypes,
5 WorkerChoiceStrategies,
6 WorkerTypes,
7 availableParallelism
8 } from '../../lib/index.mjs'
9 import { TaskFunctions } from '../benchmarks-types.mjs'
10 import {
11 LIST_FORMATTER,
12 buildPoolifierPool,
13 runPoolifierTest
14 } from '../benchmarks-utils.mjs'
15
16 const poolSize = availableParallelism()
17 const fixedThreadPool = buildPoolifierPool(
18 WorkerTypes.thread,
19 PoolTypes.fixed,
20 poolSize
21 )
22
23 const taskExecutions = 1
24 const workerData = {
25 function: TaskFunctions.jsonIntegerSerialization,
26 taskSize: 100
27 }
28
29 const poolifierSuite = new Benchmark.Suite('Poolifier')
30
31 for (const pool of [fixedThreadPool]) {
32 for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) {
33 for (const enableTasksQueue of [false, true]) {
34 poolifierSuite.add(
35 `${pool.constructor.name}|${workerChoiceStrategy}|${
36 enableTasksQueue ? 'with' : 'without'
37 } tasks queue`,
38 async () => {
39 pool.setWorkerChoiceStrategy(workerChoiceStrategy)
40 pool.enableTasksQueue(enableTasksQueue)
41 assert.strictEqual(
42 pool.opts.workerChoiceStrategy,
43 workerChoiceStrategy
44 )
45 assert.strictEqual(pool.opts.enableTasksQueue, enableTasksQueue)
46 await runPoolifierTest(pool, {
47 taskExecutions,
48 workerData
49 })
50 }
51 )
52 }
53 }
54 }
55
56 poolifierSuite
57 .on('cycle', event => {
58 console.info(event.target.toString())
59 })
60 .on('complete', function () {
61 console.info(
62 'Fastest is ' + LIST_FORMATTER.format(this.filter('fastest').map('name'))
63 )
64 fixedThreadPool.destroy()
65 })
66 .run({ async: true })