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