From c978c727a1b9913cab6146f3112a3599d59935a4 Mon Sep 17 00:00:00 2001 From: Andrey Pechkurov Date: Sun, 4 Oct 2020 19:18:32 +0300 Subject: [PATCH] add benchmark for hideStackFrames --- benchmark/misc/hidestackframes.js | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 benchmark/misc/hidestackframes.js diff --git a/benchmark/misc/hidestackframes.js b/benchmark/misc/hidestackframes.js new file mode 100644 index 00000000000000..a5774cf9aa7781 --- /dev/null +++ b/benchmark/misc/hidestackframes.js @@ -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); +}