feat: add new pool options
[poolifier.git] / benchmarks / internal / bench.mjs
1 import Benchmark from 'benchmark'
2 import {
3 Measurements,
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 poolifierSuite = new Benchmark.Suite('Poolifier', {
17 onCycle: event => {
18 console.info(event.target.toString())
19 },
20 onComplete: function () {
21 console.info(
22 'Fastest is ' + LIST_FORMATTER.format(this.filter('fastest').map('name'))
23 )
24 }
25 })
26
27 const poolSize = availableParallelism()
28 const benchmarkSettings = []
29 for (const poolType of Object.values(PoolTypes)) {
30 for (const workerType of Object.values(WorkerTypes)) {
31 if (workerType === WorkerTypes.cluster) {
32 continue
33 }
34 for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) {
35 for (const enableTasksQueue of [false, true]) {
36 if (workerChoiceStrategy === WorkerChoiceStrategies.FAIR_SHARE) {
37 for (const measurement of [Measurements.runTime, Measurements.elu]) {
38 benchmarkSettings.push([
39 `${poolType}|${workerType}|${workerChoiceStrategy}|tasks queue:${enableTasksQueue}|measurement:${measurement}`,
40 workerType,
41 poolType,
42 poolSize,
43 {
44 workerChoiceStrategy,
45 workerChoiceStrategyOptions: {
46 measurement
47 },
48 enableTasksQueue
49 }
50 ])
51 }
52 } else {
53 benchmarkSettings.push([
54 `${poolType}|${workerType}|${workerChoiceStrategy}|tasks queue:${enableTasksQueue}`,
55 workerType,
56 poolType,
57 poolSize,
58 {
59 workerChoiceStrategy,
60 enableTasksQueue
61 }
62 ])
63 }
64 }
65 }
66 }
67 }
68
69 const taskExecutions = 1
70 const workerData = {
71 function: TaskFunctions.jsonIntegerSerialization,
72 taskSize: 100
73 }
74
75 for (const [
76 name,
77 workerType,
78 poolType,
79 poolSize,
80 poolOptions
81 ] of benchmarkSettings) {
82 poolifierSuite.add(name, async () => {
83 const pool = buildPoolifierPool(workerType, poolType, poolSize, poolOptions)
84 await runPoolifierTest(pool, {
85 taskExecutions,
86 workerData
87 })
88 await pool.destroy()
89 })
90 }
91
92 poolifierSuite.run({ async: true })