mirror of
https://github.com/nodejs/node.git
synced 2025-04-29 22:40:57 +00:00

PR-URL: https://github.com/nodejs/node/pull/31188 Refs: https://github.com/nodejs/diagnostics/issues/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>
41 lines
926 B
JavaScript
41 lines
926 B
JavaScript
'use strict';
|
|
const common = require('../common.js');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
asyncHooks: ['init', 'before', 'after', 'all', 'disabled', 'none'],
|
|
connections: [50, 500]
|
|
});
|
|
|
|
function main({ asyncHooks, connections }) {
|
|
if (asyncHooks !== 'none') {
|
|
let hooks = {
|
|
init() {},
|
|
before() {},
|
|
after() {},
|
|
destroy() {},
|
|
promiseResolve() {}
|
|
};
|
|
if (asyncHooks !== 'all' || asyncHooks !== 'disabled') {
|
|
hooks = {
|
|
[asyncHooks]: () => {}
|
|
};
|
|
}
|
|
const hook = require('async_hooks').createHook(hooks);
|
|
if (asyncHooks !== 'disabled') {
|
|
hook.enable();
|
|
}
|
|
}
|
|
const server = require('../fixtures/simple-http-server.js')
|
|
.listen(common.PORT)
|
|
.on('listening', () => {
|
|
const path = '/buffer/4/4/normal/1';
|
|
|
|
bench.http({
|
|
connections,
|
|
path,
|
|
}, () => {
|
|
server.close();
|
|
});
|
|
});
|
|
}
|