diff options
Diffstat (limited to 'benchmark/_test-double-benchmarker.js')
-rw-r--r-- | benchmark/_test-double-benchmarker.js | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/benchmark/_test-double-benchmarker.js b/benchmark/_test-double-benchmarker.js index 8c2f744fbf..e2a0eb1312 100644 --- a/benchmark/_test-double-benchmarker.js +++ b/benchmark/_test-double-benchmarker.js @@ -2,6 +2,28 @@ const http = require('http'); -http.get(process.env.test_url, function() { - console.log(JSON.stringify({ throughput: 1 })); -}); +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(); |