Skip to content

Commit

Permalink
benchmark: always throw the same Error instance
Browse files Browse the repository at this point in the history
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: nodejs#34512 (comment)
  • Loading branch information
addaleax committed Jul 26, 2020
1 parent 6a7e3c0 commit 583f390
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion benchmark/async_hooks/promises.js
Expand Up @@ -31,10 +31,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);
}
}
Expand Down

0 comments on commit 583f390

Please sign in to comment.