0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/benchmark/_test-double-benchmarker.js
Joyee Cheung 98d1110721
benchmark: implement duration in http test double
PR-URL: https://github.com/nodejs/node/pull/18380
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2018-01-29 17:46:14 +08:00

30 lines
532 B
JavaScript

'use strict';
const http = require('http');
const duration = process.env.duration || 0;
const url = process.env.test_url;
const start = process.hrtime();
let throughput = 0;
function request(res) {
res.on('data', () => {});
res.on('error', () => {});
res.on('end', () => {
throughput++;
const diff = process.hrtime(start);
if (duration > 0 && diff[0] < duration) {
run();
} else {
console.log(JSON.stringify({ throughput }));
}
});
}
function run() {
http.get(url, request);
}
run();