Skip to content

Commit af7689e

Browse files
RafaelGSSaduh95
authored andcommitted
benchmark: add throws and doesNotThrow bench
PR-URL: #54734 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 456a1fe commit af7689e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

benchmark/assert/throws.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
const assert = require('assert');
5+
6+
const bench = common.createBenchmark(main, {
7+
n: [25, 2e5],
8+
method: ['throws', 'doesNotThrow'],
9+
});
10+
11+
function main({ n, method }) {
12+
const fn = assert[method];
13+
const shouldThrow = method === 'throws';
14+
15+
bench.start();
16+
for (let i = 0; i < n; ++i) {
17+
fn(() => {
18+
const err = new Error(`assert.${method}`);
19+
if (shouldThrow) {
20+
throw err;
21+
} else {
22+
return err;
23+
}
24+
});
25+
}
26+
bench.end(n);
27+
}

0 commit comments

Comments
 (0)