0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/benchmark/http/headers.js
Ruben Bridgewater 1760c23f75
benchmark: add test and all options and improve errors"
This reverts commit 4671d551cf and
contains a fix to the issue raised for the revert.

PR-URL: https://github.com/nodejs/node/pull/31755
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2020-03-09 22:35:53 +01:00

40 lines
907 B
JavaScript

'use strict';
const common = require('../common.js');
const http = require('http');
const bench = common.createBenchmark(main, {
n: [10, 1000],
len: [1, 100],
duration: 5
});
function main({ len, n, duration }) {
const headers = {
'Connection': 'keep-alive',
'Transfer-Encoding': 'chunked',
};
// TODO(BridgeAR): Change this benchmark to use grouped arguments when
// implemented. https://github.com/nodejs/node/issues/26425
const Is = [ ...Array(Math.max(n / len, 1)).keys() ];
const Js = [ ...Array(len).keys() ];
for (const i of Is) {
headers[`foo${i}`] = Js.map(() => `some header value ${i}`);
}
const server = http.createServer((req, res) => {
res.writeHead(200, headers);
res.end();
});
server.listen(common.PORT, () => {
bench.http({
path: '/',
connections: 10,
duration
}, () => {
server.close();
});
});
}