()
| 230 | } |
| 231 | |
| 232 | async function main() { |
| 233 | const iterations = Number.parseInt(process.env.BENCHMARK_ITERATIONS ?? '3', 10); |
| 234 | |
| 235 | const connection = await Connection.connect({ address: TEMPORAL_ADDRESS }); |
| 236 | const client = new Client({ connection, namespace: TEMPORAL_NAMESPACE }); |
| 237 | |
| 238 | try { |
| 239 | console.log(`Running benchmark with ${iterations} iteration(s) per mode...`); |
| 240 | |
| 241 | const inlineSerial = await runInlineBenchmark(serialDefinition, iterations, 'serial'); |
| 242 | const inlineParallel = await runInlineBenchmark(parallelDefinition, iterations, 'parallel'); |
| 243 | const temporalSerial = await runTemporalBenchmark( |
| 244 | client, |
| 245 | serialDefinition, |
| 246 | iterations, |
| 247 | 'serial', |
| 248 | ); |
| 249 | const temporalParallel = await runTemporalBenchmark( |
| 250 | client, |
| 251 | parallelDefinition, |
| 252 | iterations, |
| 253 | 'parallel', |
| 254 | ); |
| 255 | |
| 256 | const summaryRows = [inlineSerial, inlineParallel, temporalSerial, temporalParallel].map( |
| 257 | (result) => ({ |
| 258 | Engine: result.engine, |
| 259 | Mode: result.mode, |
| 260 | Runs: result.runs, |
| 261 | 'Average (ms)': result.averageMs.toFixed(2), |
| 262 | }), |
| 263 | ); |
| 264 | |
| 265 | console.table(summaryRows); |
| 266 | |
| 267 | await ensureOutputDir(); |
| 268 | const snapshotPath = join(OUTPUT_DIR, `scheduler-benchmark-${Date.now()}.json`); |
| 269 | await fs.writeFile( |
| 270 | snapshotPath, |
| 271 | JSON.stringify( |
| 272 | { |
| 273 | iterations, |
| 274 | inline: { |
| 275 | serial: inlineSerial, |
| 276 | parallel: inlineParallel, |
| 277 | }, |
| 278 | temporal: { |
| 279 | serial: temporalSerial, |
| 280 | parallel: temporalParallel, |
| 281 | }, |
| 282 | }, |
| 283 | null, |
| 284 | 2, |
| 285 | ), |
| 286 | 'utf8', |
| 287 | ); |
| 288 | console.log(`Benchmark snapshot written to ${snapshotPath}`); |
| 289 | } finally { |
no test coverage detected