Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

errors: eliminate all overhead for hidden calls #35644

Closed
wants to merge 12 commits into from
45 changes: 45 additions & 0 deletions benchmark/misc/hidestackframes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}
Loading