From a760dadec337f61dd574bbe4e96e7fb907a51a47 Mon Sep 17 00:00:00 2001 From: Raz Luvaton <16746759+rluvaton@users.noreply.github.com> Date: Sun, 7 Apr 2024 22:49:56 +0300 Subject: [PATCH] benchmark: add AbortSignal.abort benchmarks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/52408 Reviewed-By: Yagiz Nizipli Reviewed-By: Vinícius Lourenço Claro Cardoso Reviewed-By: Matteo Collina Reviewed-By: Michaël Zasso Reviewed-By: Moshe Atlow Reviewed-By: Minwoo Jung Reviewed-By: Matthew Aitken --- .../abort-signal-static-abort.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 benchmark/abort_controller/abort-signal-static-abort.js 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'); + } +}