diff --git a/benchmark/abort_controller/abort-signal-static-abort.js b/benchmark/abort_controller/abort-signal-static-abort.js new file mode 100644 index 00000000000..2b1c884a260 --- /dev/null +++ b/benchmark/abort_controller/abort-signal-static-abort.js @@ -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'); + } +}