summaryrefslogtreecommitdiff
path: root/benchmark/misc/hidestackframes.js
diff options
context:
space:
mode:
Diffstat (limited to 'benchmark/misc/hidestackframes.js')
-rw-r--r--benchmark/misc/hidestackframes.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/benchmark/misc/hidestackframes.js b/benchmark/misc/hidestackframes.js
new file mode 100644
index 0000000000..5b14f2d95b
--- /dev/null
+++ b/benchmark/misc/hidestackframes.js
@@ -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);
+}