-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark: benchmarking impacts of async hooks on promises
PR-URL: #31188 Refs: nodejs/diagnostics#124 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
- Loading branch information
1 parent
9c98d25
commit 317d2db
Showing
2 changed files
with
39 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
const { createHook } = require('async_hooks'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1e6], | ||
asyncHooks: [ | ||
'enabled', | ||
'disabled', | ||
] | ||
}); | ||
|
||
async function run(n) { | ||
for (let i = 0; i < n; i++) { | ||
await new Promise((resolve) => resolve()) | ||
.then(() => { throw new Error('foobar'); }) | ||
.catch((e) => e); | ||
} | ||
} | ||
|
||
function main({ n, asyncHooks }) { | ||
const hook = createHook({ promiseResolve() {} }); | ||
if (asyncHooks !== 'disabled') { | ||
hook.enable(); | ||
} | ||
bench.start(); | ||
run(n).then(() => { | ||
bench.end(n); | ||
}); | ||
} |