Files
node/benchmark/process/handled-rejections.js
Gürgün Dayıoğlu 012bf70908 process: optimize asyncHandledRejections by using FixedQueue
PR-URL: https://github.com/nodejs/node/pull/60854
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Ilyas Shabi <ilyasshabi94@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2026-01-02 11:40:05 +00:00

44 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../common.js');
// Benchmarks the throughput of processing many promise rejections that are
// initially unhandled, get warned, and then handled asynchronously, exercising
// asyncHandledRejections + processPromiseRejections.
//
// Note: This benchmark uses --unhandled-rejections=warn to avoid crashing
// when promises are temporarily unhandled.
const bench = common.createBenchmark(main, {
n: [1e4, 5e4, 1e5],
}, {
flags: ['--unhandled-rejections=warn'],
});
function main({ n }) {
const rejections = [];
// Suppress warning output during the benchmark
process.removeAllListeners('warning');
for (let i = 0; i < n; i++) {
rejections.push(Promise.reject(i));
}
// Wait for them to be processed as unhandled and warned.
setImmediate(() => {
setImmediate(() => {
bench.start();
for (let i = 0; i < n; i++) {
rejections[i].catch(() => {});
}
// Let processPromiseRejections drain asyncHandledRejections.
setImmediate(() => {
bench.end(n);
});
});
});
}