From 66acab9976df7d4a8eb38c27155e8fd4b2b02263 Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Tue, 3 Sep 2024 11:47:22 -0300 Subject: [PATCH] benchmark: add rejects and doesNotReject bench PR-URL: https://github.com/nodejs/node/pull/54734 Reviewed-By: Rich Trott Reviewed-By: Chemi Atlow --- benchmark/assert/rejects.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 benchmark/assert/rejects.js diff --git a/benchmark/assert/rejects.js b/benchmark/assert/rejects.js new file mode 100644 index 00000000000000..43ec500177a625 --- /dev/null +++ b/benchmark/assert/rejects.js @@ -0,0 +1,27 @@ +'use strict'; + +const common = require('../common.js'); +const assert = require('assert'); + +const bench = common.createBenchmark(main, { + n: [25, 2e5], + method: ['rejects', 'doesNotReject'], +}); + +async function main({ n, method }) { + const fn = assert[method]; + const shouldReject = method === 'rejects'; + + bench.start(); + for (let i = 0; i < n; ++i) { + await fn(async () => { + const err = new Error(`assert.${method}`); + if (shouldReject) { + throw err; + } else { + return err; + } + }); + } + bench.end(n); +}