summaryrefslogtreecommitdiff
path: root/benchmark/_test-double-benchmarker.js
diff options
context:
space:
mode:
Diffstat (limited to 'benchmark/_test-double-benchmarker.js')
-rw-r--r--benchmark/_test-double-benchmarker.js22
1 files changed, 18 insertions, 4 deletions
diff --git a/benchmark/_test-double-benchmarker.js b/benchmark/_test-double-benchmarker.js
index e2a0eb1312..b9379b907f 100644
--- a/benchmark/_test-double-benchmarker.js
+++ b/benchmark/_test-double-benchmarker.js
@@ -1,6 +1,11 @@
'use strict';
-const http = require('http');
+const myModule = process.argv[2];
+if (!['http', 'http2'].includes(myModule)) {
+ throw new Error(`Invalid module for benchmark test double: ${myModule}`);
+}
+
+const http = require(myModule);
const duration = process.env.duration || 0;
const url = process.env.test_url;
@@ -8,8 +13,8 @@ const url = process.env.test_url;
const start = process.hrtime();
let throughput = 0;
-function request(res) {
- res.on('data', () => {});
+function request(res, client) {
+ res.resume();
res.on('error', () => {});
res.on('end', () => {
throughput++;
@@ -18,12 +23,21 @@ function request(res) {
run();
} else {
console.log(JSON.stringify({ throughput }));
+ if (client) {
+ client.destroy();
+ }
}
});
}
function run() {
- http.get(url, request);
+ if (http.get) { // HTTP
+ http.get(url, request);
+ } else { // HTTP/2
+ const client = http.connect(url);
+ client.on('error', (e) => { throw e; });
+ request(client.request(), client);
+ }
}
run();