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 <targos@protonmail.com>
Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
  • Loading branch information
addaleax authored and codebytere committed Aug 5, 2020
1 parent 44e6c01 commit c4457d8
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 @@ -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);
}
}
Expand Down

0 comments on commit c4457d8

Please sign in to comment.