forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
errors: add a benchmark for hidestackframes
Add @puzpuzpuz's benchmark for the new implementation of hideStackFrames Refs: nodejs#35386 Refs: nodejs#35644
- Loading branch information
Showing
1 changed file
with
50 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,50 @@ | ||
'use strict'; | ||
|
||
const common = require('../common.js'); | ||
|
||
/* there should be no significant performance differences | ||
* between the hideStackFrames version and the direct | ||
* call version | ||
*/ | ||
const bench = common.createBenchmark(main, { | ||
type: ['hide-stackframes-throw', 'direct-call-throw', | ||
'hide-stackframes-noerr', 'direct-call-noerr'], | ||
n: [10e4] | ||
}, { | ||
flags: ['--expose-internals'] | ||
}); | ||
|
||
function main({ n, type }) { | ||
const { | ||
hideStackFrames, | ||
codes: { | ||
ERR_INVALID_ARG_TYPE, | ||
}, | ||
} = require('internal/errors'); | ||
|
||
const testfn = (value) => { | ||
if (typeof value !== 'number') { | ||
throw new ERR_INVALID_ARG_TYPE('Benchmark', 'number', value); | ||
} | ||
}; | ||
|
||
let fn = testfn; | ||
if (type.startsWith('hide-stackframe')) | ||
fn = hideStackFrames(testfn); | ||
let value = 42; | ||
if (type.endsWith('-throw')) | ||
value = 'err'; | ||
|
||
bench.start(); | ||
|
||
for (let i = 0; i < n; i++) { | ||
try { | ||
fn(value); | ||
// eslint-disable-next-line no-unused-vars | ||
} catch (e) { | ||
// No-op | ||
} | ||
} | ||
|
||
bench.end(n); | ||
} |