Skip to content

Commit c978c72

Browse files
committed
add benchmark for hideStackFrames
1 parent db4e701 commit c978c72

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

benchmark/misc/hidestackframes.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
5+
const bench = common.createBenchmark(main, {
6+
type: ['no-error', 'error'],
7+
n: [100000]
8+
}, {
9+
flags: ['--expose-internals']
10+
});
11+
12+
function main({ n, type }) {
13+
const {
14+
hideStackFrames,
15+
codes: {
16+
ERR_INVALID_ARG_TYPE,
17+
},
18+
} = require('internal/errors');
19+
20+
const fn = hideStackFrames(
21+
(value) => {
22+
if (typeof value !== 'number') {
23+
throw new ERR_INVALID_ARG_TYPE('Benchmark', 'number', value);
24+
}
25+
}
26+
);
27+
28+
let value = 'will-throw';
29+
if (type === 'no-error') {
30+
value = 42;
31+
}
32+
33+
bench.start();
34+
35+
for (let i = 0; i < n; i++) {
36+
try {
37+
fn(value);
38+
} catch (err) {
39+
// No-op
40+
}
41+
}
42+
43+
bench.end(n);
44+
}

0 commit comments

Comments
 (0)