mirror of
https://github.com/nodejs/node.git
synced 2025-04-30 23:56:58 +00:00
benchmark: add AbortSignal.abort benchmarks
PR-URL: https://github.com/nodejs/node/pull/52408 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com>
This commit is contained in:
parent
818c10e86d
commit
a760dadec3
29
benchmark/abort_controller/abort-signal-static-abort.js
Normal file
29
benchmark/abort_controller/abort-signal-static-abort.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
'use strict';
|
||||||
|
const common = require('../common.js');
|
||||||
|
|
||||||
|
const bench = common.createBenchmark(main, {
|
||||||
|
n: [5e6],
|
||||||
|
kind: ['default-reason', 'same-reason'],
|
||||||
|
});
|
||||||
|
|
||||||
|
function main({ n, kind }) {
|
||||||
|
switch (kind) {
|
||||||
|
case 'default-reason':
|
||||||
|
bench.start();
|
||||||
|
for (let i = 0; i < n; ++i)
|
||||||
|
AbortSignal.abort();
|
||||||
|
bench.end(n);
|
||||||
|
break;
|
||||||
|
case 'same-reason': {
|
||||||
|
const reason = new Error('same reason');
|
||||||
|
|
||||||
|
bench.start();
|
||||||
|
for (let i = 0; i < n; ++i)
|
||||||
|
AbortSignal.abort(reason);
|
||||||
|
bench.end(n);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw new Error('Invalid kind');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user