aboutsummaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorMomtchil Momtchev <momtchil@momtchev.com>2020-10-14 17:39:21 +0200
committerAntoine du Hamel <duhamelantoine1995@gmail.com>2020-12-22 11:09:55 +0100
commit656ce920a33272dbf24c5a5beccf57f637e7e832 (patch)
treec10d7a7c4eab34b368707169316497e04e675c6b /benchmark
parent67b9ba9afebf7477ce8706b29b3c35351d8113bd (diff)
downloadios-node-v8-656ce920a33272dbf24c5a5beccf57f637e7e832.tar.gz
ios-node-v8-656ce920a33272dbf24c5a5beccf57f637e7e832.tar.bz2
ios-node-v8-656ce920a33272dbf24c5a5beccf57f637e7e832.zip
errors: eliminate all overhead for hidden calls
Eliminate all overhead for function calls that are to be hidden from the stack traces at the expense of reduced performance for the error case Fixes: https://github.com/nodejs/node/issues/35386 PR-URL: https://github.com/nodejs/node/pull/35644 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'benchmark')
-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);
+}