0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-24 20:29:23 +01:00
nodejs/benchmark/async_hooks/http-server.js
Antoine du Hamel 997c47fba7
benchmark: add trailing commas in benchmark/async_hooks
PR-URL: https://github.com/nodejs/node/pull/46424
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2023-02-01 21:46:09 +00:00

43 lines
972 B
JavaScript

'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
asyncHooks: ['init', 'before', 'after', 'all', 'disabled', 'none'],
connections: [50, 500],
duration: 5,
});
function main({ asyncHooks, connections, duration }) {
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,
duration,
}, () => {
server.close();
});
});
}