aboutsummaryrefslogtreecommitdiff
path: root/benchmark/http
diff options
context:
space:
mode:
Diffstat (limited to 'benchmark/http')
-rw-r--r--benchmark/http/create-clientrequest.js50
1 files changed, 40 insertions, 10 deletions
diff --git a/benchmark/http/create-clientrequest.js b/benchmark/http/create-clientrequest.js
index 97316a7e80..76468a49aa 100644
--- a/benchmark/http/create-clientrequest.js
+++ b/benchmark/http/create-clientrequest.js
@@ -2,19 +2,49 @@
const common = require('../common.js');
const ClientRequest = require('http').ClientRequest;
-
+const types = Object.keys(common.urls)
+ .filter((i) => common.urls[i]
+ .startsWith('http://'));
const bench = common.createBenchmark(main, {
- len: [1, 8, 16, 32, 64, 128],
- n: [1e6]
+ // Use 'url' to avoid name clash with other http benchmark
+ url: types.concat(['wpt']),
+ arg: ['URL', 'string', 'options'],
+ e: [1]
});
-function main({ len, n }) {
- const path = '/'.repeat(len);
- const opts = { path: path, createConnection: function() {} };
+function noop() {}
- bench.start();
- for (var i = 0; i < n; i++) {
- new ClientRequest(opts);
+function main({ url: type, arg, e }) {
+ e = +e;
+ const data = common.bakeUrlData(type, e, false, false)
+ .filter((i) => i.startsWith('http://'));
+ const len = data.length;
+ var result;
+ var i;
+ if (arg === 'options') {
+ const options = data.map((i) => ({
+ path: new URL(i).path, createConnection: noop
+ }));
+ bench.start();
+ for (i = 0; i < len; i++) {
+ result = new ClientRequest(options[i]);
+ }
+ bench.end(len);
+ } else if (arg === 'URL') {
+ const options = data.map((i) => new URL(i));
+ bench.start();
+ for (i = 0; i < len; i++) {
+ result = new ClientRequest(options[i], { createConnection: noop });
+ }
+ bench.end(len);
+ } else if (arg === 'string') {
+ bench.start();
+ for (i = 0; i < len; i++) {
+ result = new ClientRequest(data[i], { createConnection: noop });
+ }
+ bench.end(len);
+ } else {
+ throw new Error(`Unknown arg type ${arg}`);
}
- bench.end(n);
+ require('assert').ok(result);
}