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: #34512 (comment)

PR-URL: #34523
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Andrey Pechkurov <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
  • Loading branch information
addaleax committed Sep 22, 2020
1 parent 9b25938 commit 3e6fce4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion benchmark/async_hooks/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,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 3e6fce4

Please sign in to comment.