forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhidestackframes.js
More file actions
45 lines (37 loc) · 857 Bytes
/
hidestackframes.js
File metadata and controls
45 lines (37 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict';
const common = require('../common.js');
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);
} catch {
// No-op
}
}
bench.end(n);
}