| 156 | }; |
| 157 | |
| 158 | async function runTemporalBenchmark( |
| 159 | client: Client, |
| 160 | definition: WorkflowDefinition, |
| 161 | iterations: number, |
| 162 | label: BenchmarkMode, |
| 163 | ): Promise<BenchmarkResult> { |
| 164 | const durations: number[] = []; |
| 165 | |
| 166 | for (let i = 0; i < iterations; i += 1) { |
| 167 | const runId = `${label}-${randomUUID()}`; |
| 168 | const start = Date.now(); |
| 169 | |
| 170 | const handle = await client.workflow.start(shipsecWorkflowRun, { |
| 171 | workflowId: runId, |
| 172 | taskQueue: TEMPORAL_TASK_QUEUE, |
| 173 | args: [ |
| 174 | { |
| 175 | runId, |
| 176 | workflowId: `benchmark-${label}`, |
| 177 | definition, |
| 178 | inputs: {}, |
| 179 | }, |
| 180 | ], |
| 181 | }); |
| 182 | |
| 183 | await handle.result(); |
| 184 | durations.push(Date.now() - start); |
| 185 | } |
| 186 | |
| 187 | const averageMs = durations.reduce((sum, value) => sum + value, 0) / durations.length; |
| 188 | |
| 189 | return { |
| 190 | engine: 'temporal', |
| 191 | mode: label, |
| 192 | runs: iterations, |
| 193 | durations, |
| 194 | averageMs, |
| 195 | }; |
| 196 | } |
| 197 | |
| 198 | async function ensureOutputDir() { |
| 199 | await fs.mkdir(OUTPUT_DIR, { recursive: true }); |