| 1 | import { exit } from 'node:process' |
| 2 | import { parseArgs } from 'node:util' |
| 3 | |
| 4 | import { |
| 5 | availableParallelism, |
| 6 | PoolTypes, |
| 7 | WorkerTypes |
| 8 | } from '../../lib/index.mjs' |
| 9 | import { TaskFunctions } from '../benchmarks-types.cjs' |
| 10 | import { |
| 11 | runPoolifierBenchmarkBenchmarkJsSuite, |
| 12 | runPoolifierBenchmarkTatamiNg |
| 13 | } from '../benchmarks-utils.mjs' |
| 14 | |
| 15 | const poolSize = availableParallelism() |
| 16 | const taskExecutions = 1 |
| 17 | const workerData = { |
| 18 | function: TaskFunctions.factorial, |
| 19 | taskSize: 50000 |
| 20 | } |
| 21 | |
| 22 | switch ( |
| 23 | parseArgs({ |
| 24 | args: process.argv, |
| 25 | options: { |
| 26 | type: { |
| 27 | type: 'string', |
| 28 | short: 't' |
| 29 | } |
| 30 | }, |
| 31 | strict: true, |
| 32 | allowPositionals: true |
| 33 | }).values.type |
| 34 | ) { |
| 35 | case 'tatami-ng': |
| 36 | await runPoolifierBenchmarkTatamiNg( |
| 37 | 'FixedThreadPool', |
| 38 | WorkerTypes.thread, |
| 39 | PoolTypes.fixed, |
| 40 | poolSize, |
| 41 | { |
| 42 | taskExecutions, |
| 43 | workerData |
| 44 | } |
| 45 | ) |
| 46 | await runPoolifierBenchmarkTatamiNg( |
| 47 | 'DynamicThreadPool', |
| 48 | WorkerTypes.thread, |
| 49 | PoolTypes.dynamic, |
| 50 | poolSize, |
| 51 | { |
| 52 | taskExecutions, |
| 53 | workerData |
| 54 | } |
| 55 | ) |
| 56 | await runPoolifierBenchmarkTatamiNg( |
| 57 | 'FixedClusterPool', |
| 58 | WorkerTypes.cluster, |
| 59 | PoolTypes.fixed, |
| 60 | poolSize, |
| 61 | { |
| 62 | taskExecutions, |
| 63 | workerData |
| 64 | } |
| 65 | ) |
| 66 | await runPoolifierBenchmarkTatamiNg( |
| 67 | 'DynamicClusterPool', |
| 68 | WorkerTypes.cluster, |
| 69 | PoolTypes.dynamic, |
| 70 | poolSize, |
| 71 | { |
| 72 | taskExecutions, |
| 73 | workerData |
| 74 | } |
| 75 | ) |
| 76 | break |
| 77 | case 'benchmark.js': |
| 78 | default: |
| 79 | await runPoolifierBenchmarkBenchmarkJsSuite( |
| 80 | 'FixedThreadPool', |
| 81 | WorkerTypes.thread, |
| 82 | PoolTypes.fixed, |
| 83 | poolSize, |
| 84 | { |
| 85 | taskExecutions, |
| 86 | workerData |
| 87 | } |
| 88 | ) |
| 89 | await runPoolifierBenchmarkBenchmarkJsSuite( |
| 90 | 'DynamicThreadPool', |
| 91 | WorkerTypes.thread, |
| 92 | PoolTypes.dynamic, |
| 93 | poolSize, |
| 94 | { |
| 95 | taskExecutions, |
| 96 | workerData |
| 97 | } |
| 98 | ) |
| 99 | await runPoolifierBenchmarkBenchmarkJsSuite( |
| 100 | 'FixedClusterPool', |
| 101 | WorkerTypes.cluster, |
| 102 | PoolTypes.fixed, |
| 103 | poolSize, |
| 104 | { |
| 105 | taskExecutions, |
| 106 | workerData |
| 107 | } |
| 108 | ) |
| 109 | await runPoolifierBenchmarkBenchmarkJsSuite( |
| 110 | 'DynamicClusterPool', |
| 111 | WorkerTypes.cluster, |
| 112 | PoolTypes.dynamic, |
| 113 | poolSize, |
| 114 | { |
| 115 | taskExecutions, |
| 116 | workerData |
| 117 | } |
| 118 | ) |
| 119 | break |
| 120 | } |
| 121 | |
| 122 | exit() |