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.
- Loading branch information
Showing
1 changed file
with
44 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,44 @@ | ||
'use strict'; | ||
|
||
const common = require('../common.js'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
type: ['no-error', 'error'], | ||
n: [100000] | ||
}, { | ||
flags: ['--expose-internals'] | ||
}); | ||
|
||
function main({ n, type }) { | ||
const { | ||
hideStackFrames, | ||
codes: { | ||
ERR_INVALID_ARG_TYPE, | ||
}, | ||
} = require('internal/errors'); | ||
|
||
const fn = hideStackFrames( | ||
(value) => { | ||
if (typeof value !== 'number') { | ||
throw new ERR_INVALID_ARG_TYPE('Benchmark', 'number', value); | ||
} | ||
} | ||
); | ||
|
||
let value = 'will-throw'; | ||
if (type === 'no-error') { | ||
value = 42; | ||
} | ||
|
||
bench.start(); | ||
|
||
for (let i = 0; i < n; i++) { | ||
try { | ||
fn(value); | ||
} catch (err) { | ||
// No-op | ||
} | ||
} | ||
|
||
bench.end(n); | ||
} |