Skip to content

Commit 317d2db

Browse 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

2 files changed

Lines changed: 39 additions & 9 deletions

File tree

‎benchmark/async_hooks/http-server.js‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ function main({ asyncHooks, connections }) {
2626
}
2727
}
2828
constserver=require('../fixtures/simple-http-server.js')
29-
.listen(common.PORT)
30-
.on('listening',()=>{
31-
constpath='/buffer/4/4/normal/1';
29+
.listen(common.PORT)
30+
.on('listening',()=>{
31+
constpath='/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
}

‎benchmark/async_hooks/promises.js‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
constcommon=require('../common.js');
3+
const{ createHook }=require('async_hooks');
4+
5+
constbench=common.createBenchmark(main,{
6+
n: [1e6],
7+
asyncHooks: [
8+
'enabled',
9+
'disabled',
10+
]
11+
});
12+
13+
asyncfunctionrun(n){
14+
for(leti=0;i<n;i++){
15+
awaitnewPromise((resolve)=>resolve())
16+
.then(()=>{thrownewError('foobar');})
17+
.catch((e)=>e);
18+
}
19+
}
20+
21+
functionmain({ n, asyncHooks }){
22+
consthook=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)