From c4457d873ffa6b04c51a7e6d3cac500045ea30b3 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Mon, 27 Jul 2020 01:11:38 +0200 Subject: [PATCH] benchmark: always throw the same Error instance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stack trace capturing currently accounts for 40 % of the benchmark running time. Always throwing the same exception object removes that overhead and lets the benchmark be more focused on what it is supposed to measure. Refs: https://github.com/nodejs/node/pull/34512#issuecomment-663977271 PR-URL: https://github.com/nodejs/node/pull/34523 Reviewed-By: Michaël Zasso Reviewed-By: Andrey Pechkurov Reviewed-By: Ruben Bridgewater Reviewed-By: Luigi Pinca Reviewed-By: Gerhard Stöbich --- benchmark/async_hooks/promises.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/benchmark/async_hooks/promises.js b/benchmark/async_hooks/promises.js index 9927ec0dc504e9..d60ae70192c8cb 100644 --- a/benchmark/async_hooks/promises.js +++ b/benchmark/async_hooks/promises.js @@ -37,10 +37,11 @@ const bench = common.createBenchmark(main, { ] }); +const err = new Error('foobar'); async function run(n) { for (let i = 0; i < n; i++) { await new Promise((resolve) => resolve()) - .then(() => { throw new Error('foobar'); }) + .then(() => { throw err; }) .catch((e) => e); } }