File tree Expand file tree Collapse file tree 2 files changed +39
-9
lines changed Expand file tree Collapse file tree 2 files changed +39
-9
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments