feat: add initial continous benchmarking
[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 poolSize = availableParallelism()
17 const pools = []
18 for (const poolType of Object.values(PoolTypes)) {
19 for (const workerType of Object.values(WorkerTypes)) {
20 if (workerType === WorkerTypes.cluster) {
21 continue
22 }
23 for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) {
24 for (const enableTasksQueue of [false]) {
25 if (workerChoiceStrategy === WorkerChoiceStrategies.FAIR_SHARE) {
26 for (const measurement of [Measurements.runTime, Measurements.elu]) {
27 pools.push([
28 `${poolType}|${workerType}|${workerChoiceStrategy}|tasks queue:${enableTasksQueue}|measurement:${measurement}`,
29 buildPoolifierPool(workerType, poolType, poolSize, {
30 workerChoiceStrategy,
31 workerChoiceStrategyOptions: {
32 measurement
33 },
34 enableTasksQueue
35 })
36 ])
37 }
38 } else {
39 pools.push([
40 `${poolType}|${workerType}|${workerChoiceStrategy}|tasks queue:${enableTasksQueue}`,
41 buildPoolifierPool(workerType, poolType, poolSize, {
42 workerChoiceStrategy,
43 enableTasksQueue
44 })
45 ])
46 }
47 }
48 }
49 }
50 }
51
52 const taskExecutions = 1
53 const workerData = {
54 function: TaskFunctions.jsonIntegerSerialization,
55 taskSize: 100
56 }
57
58 const suite = new Benchmark.Suite('Poolifier')
59 for (const [name, pool] of pools) {
60 suite.add(name, async () => {
61 await runPoolifierTest(pool, {
62 taskExecutions,
63 workerData
64 })
65 })
66 }
67
68 suite
69 .on('cycle', event => {
70 console.info(event.target.toString())
71 })
72 .on('complete', function () {
73 console.info(
74 'Fastest is ' + LIST_FORMATTER.format(this.filter('fastest').map('name'))
75 )
76 // eslint-disable-next-line n/no-process-exit
77 process.exit()
78 })
79 .run({ async: true, maxTime: 120 })