|
7 | 7 | rmSync, |
8 | 8 | writeFileSync, |
9 | 9 | } from 'node:fs' |
10 | | -import { bench, group, run } from '@poolifier/tatami-ng' |
| 10 | +import { Bench } from 'tinybench' |
11 | 11 | import { |
12 | 12 | DynamicThreadPool, |
13 | 13 | FixedThreadPool, |
@@ -144,87 +144,6 @@ export const runPoolifierBenchmarkDenoBench = ( |
144 | 144 | } |
145 | 145 | } |
146 | 146 |
|
147 | | -export const runPoolifierBenchmarkTatamiNg = async ( |
148 | | - name, |
149 | | - workerType, |
150 | | - poolType, |
151 | | - poolSize, |
152 | | - benchmarkReporter, |
153 | | - { taskExecutions, workerData }, |
154 | | -) => { |
155 | | - try { |
156 | | - const pool = buildPoolifierPool(workerType, poolType, poolSize) |
157 | | - for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) { |
158 | | - for (const enableTasksQueue of [false, true]) { |
159 | | - if (workerChoiceStrategy === WorkerChoiceStrategies.FAIR_SHARE) { |
160 | | - for (const measurement of [Measurements.runTime]) { |
161 | | - group(name, () => { |
162 | | - bench( |
163 | | - `${name} with ${workerChoiceStrategy}, with ${measurement} and ${ |
164 | | - enableTasksQueue ? 'with' : 'without' |
165 | | - } tasks queue`, |
166 | | - async () => { |
167 | | - await runPoolifierPool(pool, { |
168 | | - taskExecutions, |
169 | | - workerData, |
170 | | - }) |
171 | | - }, |
172 | | - { |
173 | | - before: () => { |
174 | | - pool.setWorkerChoiceStrategy(workerChoiceStrategy, { |
175 | | - measurement, |
176 | | - }) |
177 | | - pool.enableTasksQueue(enableTasksQueue) |
178 | | - strictEqual( |
179 | | - pool.opts.workerChoiceStrategy, |
180 | | - workerChoiceStrategy, |
181 | | - ) |
182 | | - strictEqual(pool.opts.enableTasksQueue, enableTasksQueue) |
183 | | - strictEqual( |
184 | | - pool.opts.workerChoiceStrategyOptions.measurement, |
185 | | - measurement, |
186 | | - ) |
187 | | - }, |
188 | | - }, |
189 | | - ) |
190 | | - }) |
191 | | - } |
192 | | - } else { |
193 | | - group(name, () => { |
194 | | - bench( |
195 | | - `${name} with ${workerChoiceStrategy} and ${ |
196 | | - enableTasksQueue ? 'with' : 'without' |
197 | | - } tasks queue`, |
198 | | - async () => { |
199 | | - await runPoolifierPool(pool, { |
200 | | - taskExecutions, |
201 | | - workerData, |
202 | | - }) |
203 | | - }, |
204 | | - { |
205 | | - before: () => { |
206 | | - pool.setWorkerChoiceStrategy(workerChoiceStrategy) |
207 | | - pool.enableTasksQueue(enableTasksQueue) |
208 | | - strictEqual( |
209 | | - pool.opts.workerChoiceStrategy, |
210 | | - workerChoiceStrategy, |
211 | | - ) |
212 | | - strictEqual(pool.opts.enableTasksQueue, enableTasksQueue) |
213 | | - }, |
214 | | - }, |
215 | | - ) |
216 | | - }) |
217 | | - } |
218 | | - } |
219 | | - } |
220 | | - const report = await run({ reporter: benchmarkReporter }) |
221 | | - await pool.destroy() |
222 | | - return report |
223 | | - } catch (error) { |
224 | | - console.error(error) |
225 | | - } |
226 | | -} |
227 | | - |
228 | 147 | const jsonIntegerSerialization = (n) => { |
229 | 148 | for (let i = 0; i < n; i++) { |
230 | 149 | const o = { |
@@ -330,3 +249,104 @@ export const runtime = (() => { |
330 | 249 | if (isBrowser) return JSRuntime.browser |
331 | 250 | throw new Error('Unsupported JavaScript runtime environment') |
332 | 251 | })() |
| 252 | + |
| 253 | +export const runPoolifierBenchmarkTinyBench = async ( |
| 254 | + name, |
| 255 | + workerType, |
| 256 | + poolType, |
| 257 | + poolSize, |
| 258 | + { taskExecutions, workerData }, |
| 259 | +) => { |
| 260 | + try { |
| 261 | + const bench = new Bench() |
| 262 | + const pool = buildPoolifierPool(workerType, poolType, poolSize) |
| 263 | + |
| 264 | + for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) { |
| 265 | + for (const enableTasksQueue of [false, true]) { |
| 266 | + if (workerChoiceStrategy === WorkerChoiceStrategies.FAIR_SHARE) { |
| 267 | + for (const measurement of [Measurements.runTime]) { |
| 268 | + const taskName = |
| 269 | + `${name} with ${workerChoiceStrategy}, with ${measurement} and ${ |
| 270 | + enableTasksQueue ? 'with' : 'without' |
| 271 | + } tasks queue` |
| 272 | + |
| 273 | + bench.add( |
| 274 | + taskName, |
| 275 | + async () => { |
| 276 | + await runPoolifierPool(pool, { |
| 277 | + taskExecutions, |
| 278 | + workerData, |
| 279 | + }) |
| 280 | + }, |
| 281 | + { |
| 282 | + beforeAll: () => { |
| 283 | + pool.setWorkerChoiceStrategy(workerChoiceStrategy, { |
| 284 | + measurement, |
| 285 | + }) |
| 286 | + pool.enableTasksQueue(enableTasksQueue) |
| 287 | + strictEqual( |
| 288 | + pool.opts.workerChoiceStrategy, |
| 289 | + workerChoiceStrategy, |
| 290 | + ) |
| 291 | + strictEqual(pool.opts.enableTasksQueue, enableTasksQueue) |
| 292 | + strictEqual( |
| 293 | + pool.opts.workerChoiceStrategyOptions.measurement, |
| 294 | + measurement, |
| 295 | + ) |
| 296 | + }, |
| 297 | + }, |
| 298 | + ) |
| 299 | + } |
| 300 | + } else { |
| 301 | + const taskName = `${name} with ${workerChoiceStrategy} and ${ |
| 302 | + enableTasksQueue ? 'with' : 'without' |
| 303 | + } tasks queue` |
| 304 | + |
| 305 | + bench.add( |
| 306 | + taskName, |
| 307 | + async () => { |
| 308 | + await runPoolifierPool(pool, { |
| 309 | + taskExecutions, |
| 310 | + workerData, |
| 311 | + }) |
| 312 | + }, |
| 313 | + { |
| 314 | + beforeAll: () => { |
| 315 | + pool.setWorkerChoiceStrategy(workerChoiceStrategy) |
| 316 | + pool.enableTasksQueue(enableTasksQueue) |
| 317 | + strictEqual( |
| 318 | + pool.opts.workerChoiceStrategy, |
| 319 | + workerChoiceStrategy, |
| 320 | + ) |
| 321 | + strictEqual(pool.opts.enableTasksQueue, enableTasksQueue) |
| 322 | + }, |
| 323 | + }, |
| 324 | + ) |
| 325 | + } |
| 326 | + } |
| 327 | + } |
| 328 | + |
| 329 | + const tasks = await bench.run() |
| 330 | + console.table(bench.table()) |
| 331 | + await pool.destroy() |
| 332 | + |
| 333 | + const bmfResults = {} |
| 334 | + for (const task of tasks) { |
| 335 | + bmfResults[task.name] = { |
| 336 | + latency: { |
| 337 | + value: task.result.latency.mean, |
| 338 | + lower_value: task.result.latency.mean - task.result.latency.sd, |
| 339 | + upper_value: task.result.latency.mean + task.result.latency.sd, |
| 340 | + }, |
| 341 | + throughput: { |
| 342 | + value: task.result.throughput.mean, |
| 343 | + lower_value: task.result.throughput.mean - task.result.throughput.sd, |
| 344 | + upper_value: task.result.throughput.mean + task.result.throughput.sd, |
| 345 | + }, |
| 346 | + } |
| 347 | + } |
| 348 | + return bmfResults |
| 349 | + } catch (error) { |
| 350 | + console.error(error) |
| 351 | + } |
| 352 | +} |
0 commit comments