Skip to content

Commit b23e669

Browse files
committed
add benchmark utility for isNativeError function
1 parent 09f0ef2 commit b23e669

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

benchmark/util/is-native-error.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
const args = {
6+
true: new Error('test'),
7+
falsePrimitive: 42,
8+
falseObject: { foo: 'bar' },
9+
};
10+
11+
const bench = common.createBenchmark(
12+
main,
13+
{
14+
argument: ['true', 'falsePrimitive', 'falseObject'],
15+
version: ['native', 'js'],
16+
n: [1e6],
17+
},
18+
{
19+
flags: ['--expose-internals', '--no-warnings'],
20+
},
21+
);
22+
23+
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;
28+
const arg = args[argument];
29+
30+
bench.start();
31+
for (let iteration = 0; iteration < n; iteration++) {
32+
func(arg);
33+
}
34+
bench.end(n);
35+
}

bytes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 1c8d800e2a4a6c32f55784bcb3da41547b1051c8

0 commit comments

Comments
 (0)