mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Co-authored-by: Jarred-Sumner <Jarred-Sumner@users.noreply.github.com> Co-authored-by: Georgijs Vilums <=> Co-authored-by: Georgijs <48869301+gvilums@users.noreply.github.com> Co-authored-by: Georgijs Vilums <georgijs.vilums@gmail.com> Co-authored-by: gvilums <gvilums@users.noreply.github.com>
43 lines
1.0 KiB
JavaScript
43 lines
1.0 KiB
JavaScript
import { bench, run } from "../node_modules/mitata/src/cli.mjs";
|
|
|
|
let count = 20_000_000;
|
|
const batchSize = 1_000_000;
|
|
console.time("Run");
|
|
|
|
let { promise, resolve, reject } = Promise.withResolvers();
|
|
let remaining = count;
|
|
|
|
if (batchSize === 0) {
|
|
for (let i = 0; i < count; i++) {
|
|
setTimeout(() => {
|
|
remaining--;
|
|
if (remaining === 0) {
|
|
resolve();
|
|
}
|
|
}, 0);
|
|
}
|
|
await promise;
|
|
} else {
|
|
for (let i = 0; i < count; i += batchSize) {
|
|
let batch = Math.min(batchSize, count - i);
|
|
console.time("Batch " + i + " - " + (i + batch));
|
|
let { promise: batchPromise, resolve: batchResolve } = Promise.withResolvers();
|
|
let remaining = batch;
|
|
for (let j = 0; j < batch; j++) {
|
|
setTimeout(() => {
|
|
remaining--;
|
|
if (remaining === 0) {
|
|
batchResolve();
|
|
}
|
|
}, 0);
|
|
}
|
|
await batchPromise;
|
|
console.timeEnd("Batch " + i + " - " + (i + batch));
|
|
}
|
|
}
|
|
|
|
const fmt = new Intl.NumberFormat();
|
|
console.log("Executed", fmt.format(count), "timers");
|
|
console.timeEnd("Run");
|
|
process.exit(0);
|