1'use strict'; 2const common = require('../common.js'); 3 4const bench = common.createBenchmark(main, { 5 asyncHooks: ['init', 'before', 'after', 'all', 'disabled', 'none'], 6 connections: [50, 500], 7 duration: 5 8}); 9 10function main({ asyncHooks, connections, duration }) { 11 if (asyncHooks !== 'none') { 12 let hooks = { 13 init() {}, 14 before() {}, 15 after() {}, 16 destroy() {}, 17 promiseResolve() {} 18 }; 19 if (asyncHooks !== 'all' || asyncHooks !== 'disabled') { 20 hooks = { 21 [asyncHooks]: () => {} 22 }; 23 } 24 const hook = require('async_hooks').createHook(hooks); 25 if (asyncHooks !== 'disabled') { 26 hook.enable(); 27 } 28 } 29 const server = require('../fixtures/simple-http-server.js') 30 .listen(common.PORT) 31 .on('listening', () => { 32 const path = '/buffer/4/4/normal/1'; 33 34 bench.http({ 35 connections, 36 path, 37 duration 38 }, () => { 39 server.close(); 40 }); 41 }); 42} 43