summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/_http-benchmarkers.js9
-rw-r--r--benchmark/_test-double-benchmarker.js28
2 files changed, 31 insertions, 6 deletions
diff --git a/benchmark/_http-benchmarkers.js b/benchmark/_http-benchmarkers.js
index 54b7481afa..55ebcc96ba 100644
--- a/benchmark/_http-benchmarkers.js
+++ b/benchmark/_http-benchmarkers.js
@@ -89,11 +89,14 @@ class TestDoubleBenchmarker {
}
create(options) {
+ const env = Object.assign({
+ duration: options.duration,
+ test_url: `http://127.0.0.1:${options.port}${options.path}`,
+ }, process.env);
+
const child = child_process.fork(this.executable, {
silent: true,
- env: Object.assign({}, process.env, {
- test_url: `http://127.0.0.1:${options.port}${options.path}`
- })
+ env
});
return child;
}
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();