summaryrefslogtreecommitdiff
path: root/benchmark/_test-double-benchmarker.js
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2018-10-24 19:23:25 -0700
committerRich Trott <rtrott@gmail.com>2018-10-29 11:39:32 -0700
commit2812759f9352e2d180aeea8c1999dd2c6ab36371 (patch)
treeb974f51a2652cc410c62d21f40c1737e87f47c83 /benchmark/_test-double-benchmarker.js
parent2f1c356d7abe4949b5ee68e0724ed7e493fc03e1 (diff)
downloadandroid-node-v8-2812759f9352e2d180aeea8c1999dd2c6ab36371.tar.gz
android-node-v8-2812759f9352e2d180aeea8c1999dd2c6ab36371.tar.bz2
android-node-v8-2812759f9352e2d180aeea8c1999dd2c6ab36371.zip
test: add test-benchmark-http2
PR-URL: https://github.com/nodejs/node/pull/23863 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com>
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();