Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions benchmark/util/is-native-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

const common = require('../common');

const args = {
true: new Error('test'),
falsePrimitive: 42,
falseObject: { foo: 'bar' },
};

const bench = common.createBenchmark(
main,
{
argument: ['true', 'falsePrimitive', 'falseObject'],
version: ['native', 'js'],
n: [1e6],
},
{
flags: ['--expose-internals', '--no-warnings'],
},
);

function main({ argument, version, n }) {
const util = common.binding('util');
const types = require('internal/util/types');

const func = { native: util, js: types }[version].isNativeError;
const arg = args[argument];

bench.start();
for (let iteration = 0; iteration < n; iteration++) {
func(arg);
}
bench.end(n);
}
Loading