Skip to content

Commit

Permalink
benchmark: add rejects and doesNotReject bench
Browse files Browse the repository at this point in the history
PR-URL: #54734
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
  • Loading branch information
RafaelGSS authored and nodejs-github-bot committed Sep 5, 2024
1 parent 0b283c2 commit b262381
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions benchmark/assert/rejects.js
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit b262381

Please sign in to comment.