Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 317d2db

Browse filesBrowse files
legendecasMylesBorins
authored andcommitted
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>
1 parent 9c98d25 commit 317d2db
Copy full SHA for 317d2db

File tree

Expand file treeCollapse file tree

2 files changed

+39
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+39
-9
lines changed
Open diff view settings
Collapse file

‎benchmark/async_hooks/http-server.js‎

Copy file name to clipboardExpand all lines: benchmark/async_hooks/http-server.js
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ function main({ asyncHooks, connections }) {
2626
}
2727
}
2828
const server = require('../fixtures/simple-http-server.js')
29-
.listen(common.PORT)
30-
.on('listening', () => {
31-
const path = '/buffer/4/4/normal/1';
29+
.listen(common.PORT)
30+
.on('listening', () => {
31+
const path = '/buffer/4/4/normal/1';
3232

33-
bench.http({
34-
connections,
35-
path,
36-
}, () => {
37-
server.close();
33+
bench.http({
34+
connections,
35+
path,
36+
}, () => {
37+
server.close();
38+
});
3839
});
39-
});
4040
}
Collapse file

‎benchmark/async_hooks/promises.js‎

Copy file name to clipboard
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const { createHook } = require('async_hooks');
4+
5+
const bench = common.createBenchmark(main, {
6+
n: [1e6],
7+
asyncHooks: [
8+
'enabled',
9+
'disabled',
10+
]
11+
});
12+
13+
async function run(n) {
14+
for (let i = 0; i < n; i++) {
15+
await new Promise((resolve) => resolve())
16+
.then(() => { throw new Error('foobar'); })
17+
.catch((e) => e);
18+
}
19+
}
20+
21+
function main({ n, asyncHooks }) {
22+
const hook = createHook({ promiseResolve() {} });
23+
if (asyncHooks !== 'disabled') {
24+
hook.enable();
25+
}
26+
bench.start();
27+
run(n).then(() => {
28+
bench.end(n);
29+
});
30+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.