Skip to content

Commit 8c79e29

Browse files
committed
add benchmark utility for isNativeError function
1 parent 6b26012 commit 8c79e29

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,24 @@ const bench = common.createBenchmark(
1212
main,
1313
{
1414
argument: ['true'],
15-
version: ['instanceof', 'isError'],
15+
version: ['native'],
1616
n: [1e6],
1717
},
18+
{
19+
flags: ['--expose-internals', '--no-warnings'],
20+
},
1821
);
1922

2023
function main({ argument, version, n }) {
24+
const util = common.binding('util');
25+
const types = require('internal/util/types');
26+
27+
const func = { native: util, js: types }[version].isNativeError;
2128
const arg = args[argument];
22-
const func = version === 'isError' ? Error.isError : (v) => v instanceof Error;
2329

2430
bench.start();
2531
let result;
26-
for (let i = 0; i < n; i++) {
32+
for (let iteration = 0; iteration < n; iteration++) {
2733
result = func(arg);
2834
}
2935
bench.end(n);

0 commit comments

Comments
 (0)