Skip to content

Commit ef63bb2

Browse files
joyeecheungrvagg
authored andcommitted
benchmark: support URL inputs in create-clientrequest
This patch adds the option in the create-clientrequest benchmark to accept URL inputs (as strings or as URL objects) so we can measure the impact of URL parsing in a more sophisticated use case. PR-URL: #24302 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent f5d4db1 commit ef63bb2

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

benchmark/http/create-clientrequest.js

+40-10
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,49 @@
22

33
const common = require('../common.js');
44
const ClientRequest = require('http').ClientRequest;
5-
5+
const types = Object.keys(common.urls)
6+
.filter((i) => common.urls[i]
7+
.startsWith('http://'));
68
const bench = common.createBenchmark(main, {
7-
len: [1, 8, 16, 32, 64, 128],
8-
n: [1e6]
9+
// Use 'url' to avoid name clash with other http benchmark
10+
url: types.concat(['wpt']),
11+
arg: ['URL', 'string', 'options'],
12+
e: [1]
913
});
1014

11-
function main({ len, n }) {
12-
const path = '/'.repeat(len);
13-
const opts = { path: path, createConnection: function() {} };
15+
function noop() {}
1416

15-
bench.start();
16-
for (var i = 0; i < n; i++) {
17-
new ClientRequest(opts);
17+
function main({ url: type, arg, e }) {
18+
e = +e;
19+
const data = common.bakeUrlData(type, e, false, false)
20+
.filter((i) => i.startsWith('http://'));
21+
const len = data.length;
22+
var result;
23+
var i;
24+
if (arg === 'options') {
25+
const options = data.map((i) => ({
26+
path: new URL(i).path, createConnection: noop
27+
}));
28+
bench.start();
29+
for (i = 0; i < len; i++) {
30+
result = new ClientRequest(options[i]);
31+
}
32+
bench.end(len);
33+
} else if (arg === 'URL') {
34+
const options = data.map((i) => new URL(i));
35+
bench.start();
36+
for (i = 0; i < len; i++) {
37+
result = new ClientRequest(options[i], { createConnection: noop });
38+
}
39+
bench.end(len);
40+
} else if (arg === 'string') {
41+
bench.start();
42+
for (i = 0; i < len; i++) {
43+
result = new ClientRequest(data[i], { createConnection: noop });
44+
}
45+
bench.end(len);
46+
} else {
47+
throw new Error(`Unknown arg type ${arg}`);
1848
}
19-
bench.end(n);
49+
require('assert').ok(result);
2050
}

test/benchmark/test-benchmark-http.js

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ runBenchmark('http',
1515
[
1616
'benchmarker=test-double-http',
1717
'c=1',
18+
'e=0',
19+
'url=long',
20+
'arg=string',
1821
'chunkedEnc=true',
1922
'chunks=0',
2023
'dur=0.1',

0 commit comments

Comments
 (0)