• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common.js');
4const http = require('http');
5
6const bench = common.createBenchmark(main, {
7  n: [10, 600],
8  len: [1, 100],
9  duration: 5,
10});
11
12function main({ len, n, duration }) {
13  const headers = {
14    'Connection': 'keep-alive',
15    'Transfer-Encoding': 'chunked',
16  };
17
18  // TODO(BridgeAR): Change this benchmark to use grouped arguments when
19  // implemented. https://github.com/nodejs/node/issues/26425
20  const Is = [ ...Array(Math.max(n / len, 1)).keys() ];
21  const Js = [ ...Array(len).keys() ];
22  for (const i of Is) {
23    headers[`foo${i}`] = Js.map(() => `some header value ${i}`);
24  }
25
26  const server = http.createServer((req, res) => {
27    res.writeHead(200, headers);
28    res.end();
29  });
30  server.listen(0, () => {
31    bench.http({
32      path: '/',
33      connections: 10,
34      duration,
35      port: server.address().port,
36    }, () => {
37      server.close();
38    });
39  });
40}
41