Skip to content

Commit 583f390

Browse files
committed
benchmark: always throw the same Error instance
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)
1 parent 6a7e3c0 commit 583f390

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

benchmark/async_hooks/promises.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ const bench = common.createBenchmark(main, {
3131
]
3232
});
3333

34+
const err = new Error('foobar');
3435
async function run(n) {
3536
for (let i = 0; i < n; i++) {
3637
await new Promise((resolve) => resolve())
37-
.then(() => { throw new Error('foobar'); })
38+
.then(() => { throw err; })
3839
.catch((e) => e);
3940
}
4041
}

0 commit comments

Comments
 (0)