(res, client)
| 19 | let throughput = 0; |
| 20 | |
| 21 | function request(res, client) { |
| 22 | res.resume(); |
| 23 | res.on('error', () => {}); |
| 24 | res.on('end', () => { |
| 25 | throughput++; |
| 26 | const [sec, nanosec] = process.hrtime(start); |
| 27 | const ms = sec * 1000 + nanosec / 1e6; |
| 28 | if (ms < duration * 1000) { |
| 29 | run(); |
| 30 | } else { |
| 31 | console.log(JSON.stringify({ throughput })); |
| 32 | if (client) { |
| 33 | client.destroy(); |
| 34 | process.exit(0); |
| 35 | } |
| 36 | } |
| 37 | }); |
| 38 | } |
| 39 | |
| 40 | function run() { |
| 41 | if (http.get) { // HTTP or HTTPS |