| 1 | import { writeFileSync } from 'node:fs' |
| 2 | import { env } from 'node:process' |
| 3 | // eslint-disable-next-line n/no-unsupported-features/node-builtins |
| 4 | import { parseArgs } from 'node:util' |
| 5 | |
| 6 | import { |
| 7 | availableParallelism, |
| 8 | PoolTypes, |
| 9 | WorkerTypes, |
| 10 | } from '../../lib/index.mjs' |
| 11 | import { TaskFunctions } from '../benchmarks-types.cjs' |
| 12 | import { |
| 13 | convertTatamiNgToBmf, |
| 14 | runPoolifierBenchmarkTatamiNg, |
| 15 | } from '../benchmarks-utils.mjs' |
| 16 | |
| 17 | const poolSize = availableParallelism() |
| 18 | const taskExecutions = 1 |
| 19 | const workerData = { |
| 20 | function: TaskFunctions.factorial, |
| 21 | taskSize: 1000, |
| 22 | } |
| 23 | const benchmarkReportFile = 'benchmark-report.json' |
| 24 | let benchmarkReport |
| 25 | |
| 26 | switch ( |
| 27 | parseArgs({ |
| 28 | args: process.argv, |
| 29 | options: { |
| 30 | type: { |
| 31 | type: 'string', |
| 32 | short: 't', |
| 33 | }, |
| 34 | }, |
| 35 | strict: true, |
| 36 | allowPositionals: true, |
| 37 | }).values.type |
| 38 | ) { |
| 39 | case 'tatami-ng': |
| 40 | default: |
| 41 | benchmarkReport = convertTatamiNgToBmf( |
| 42 | await runPoolifierBenchmarkTatamiNg( |
| 43 | 'FixedThreadPool', |
| 44 | WorkerTypes.thread, |
| 45 | PoolTypes.fixed, |
| 46 | poolSize, |
| 47 | { |
| 48 | taskExecutions, |
| 49 | workerData, |
| 50 | } |
| 51 | ) |
| 52 | ) |
| 53 | benchmarkReport = { |
| 54 | ...benchmarkReport, |
| 55 | ...convertTatamiNgToBmf( |
| 56 | await runPoolifierBenchmarkTatamiNg( |
| 57 | 'DynamicThreadPool', |
| 58 | WorkerTypes.thread, |
| 59 | PoolTypes.dynamic, |
| 60 | poolSize, |
| 61 | { |
| 62 | taskExecutions, |
| 63 | workerData, |
| 64 | } |
| 65 | ) |
| 66 | ), |
| 67 | } |
| 68 | benchmarkReport = { |
| 69 | ...benchmarkReport, |
| 70 | ...convertTatamiNgToBmf( |
| 71 | await runPoolifierBenchmarkTatamiNg( |
| 72 | 'FixedClusterPool', |
| 73 | WorkerTypes.cluster, |
| 74 | PoolTypes.fixed, |
| 75 | poolSize, |
| 76 | { |
| 77 | taskExecutions, |
| 78 | workerData, |
| 79 | } |
| 80 | ) |
| 81 | ), |
| 82 | } |
| 83 | benchmarkReport = { |
| 84 | ...benchmarkReport, |
| 85 | ...convertTatamiNgToBmf( |
| 86 | await runPoolifierBenchmarkTatamiNg( |
| 87 | 'DynamicClusterPool', |
| 88 | WorkerTypes.cluster, |
| 89 | PoolTypes.dynamic, |
| 90 | poolSize, |
| 91 | { |
| 92 | taskExecutions, |
| 93 | workerData, |
| 94 | } |
| 95 | ) |
| 96 | ), |
| 97 | } |
| 98 | // eslint-disable-next-line @typescript-eslint/no-unused-expressions |
| 99 | env.CI != null && |
| 100 | writeFileSync(benchmarkReportFile, JSON.stringify(benchmarkReport)) |
| 101 | break |
| 102 | } |