forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark: add throws and doesNotThrow bench
PR-URL: nodejs#54734 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: ['throws', 'doesNotThrow'], | ||
}); | ||
|
||
function main({ n, method }) { | ||
const fn = assert[method]; | ||
const shouldThrow = method === 'throws'; | ||
|
||
bench.start(); | ||
for (let i = 0; i < n; ++i) { | ||
fn(() => { | ||
const err = new Error(`assert.${method}`); | ||
if (shouldThrow) { | ||
throw err; | ||
} else { | ||
return err; | ||
} | ||
}); | ||
} | ||
bench.end(n); | ||
} |