mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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>
44 lines
1.1 KiB
JavaScript
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);
|
|
});
|
|
});
|
|
});
|
|
}
|