Skip to content

Commit

Permalink
benchmark: add AbortSignal.abort benchmarks
Browse files Browse the repository at this point in the history
PR-URL: #52408
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Matthew Aitken <[email protected]>
  • Loading branch information
rluvaton authored and marco-ippolito committed May 3, 2024
1 parent 55a3fbc commit f8ad300
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions benchmark/abort_controller/abort-signal-static-abort.js
Original file line number Diff line number Diff line change
@@ -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');
}
}

0 comments on commit f8ad300

Please sign in to comment.