Skip to content

Commit 6db777f

Browse files
RafaelGSStargos
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 8f10156 commit 6db777f

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

‎benchmark/assert/throws.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
constcommon=require('../common.js');
4+
constassert=require('assert');
5+
6+
constbench=common.createBenchmark(main,{
7+
n: [25,2e5],
8+
method: ['throws','doesNotThrow'],
9+
});
10+
11+
functionmain({ n, method }){
12+
constfn=assert[method];
13+
constshouldThrow=method==='throws';
14+
15+
bench.start();
16+
for(leti=0;i<n;++i){
17+
fn(()=>{
18+
consterr=newError(`assert.${method}`);
19+
if(shouldThrow){
20+
throwerr;
21+
}else{
22+
returnerr;
23+
}
24+
});
25+
}
26+
bench.end(n);
27+
}

0 commit comments

Comments
 (0)