Skip to content

Commit

Permalink
add benchmark for hideStackFrames
Browse files Browse the repository at this point in the history
  • Loading branch information
puzpuzpuz committed Oct 4, 2020
1 parent db4e701 commit c978c72
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions benchmark/misc/hidestackframes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';

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

const bench = common.createBenchmark(main, {
type: ['no-error', 'error'],
n: [100000]
}, {
flags: ['--expose-internals']
});

function main({ n, type }) {
const {
hideStackFrames,
codes: {
ERR_INVALID_ARG_TYPE,
},
} = require('internal/errors');

const fn = hideStackFrames(
(value) => {
if (typeof value !== 'number') {
throw new ERR_INVALID_ARG_TYPE('Benchmark', 'number', value);
}
}
);

let value = 'will-throw';
if (type === 'no-error') {
value = 42;
}

bench.start();

for (let i = 0; i < n; i++) {
try {
fn(value);
} catch (err) {
// No-op
}
}

bench.end(n);
}

0 comments on commit c978c72

Please sign in to comment.