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

2 files changed

Lines changed: 43 additions & 10 deletions

File tree

‎benchmark/http/create-clientrequest.js‎

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,49 @@
22

33
constcommon=require('../common.js');
44
constClientRequest=require('http').ClientRequest;
5-
5+
consttypes=Object.keys(common.urls)
6+
.filter((i)=>common.urls[i]
7+
.startsWith('http://'));
68
constbench=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-
functionmain({ len, n }){
12-
constpath='/'.repeat(len);
13-
constopts={path: path,createConnection: function(){}};
15+
functionnoop(){}
1416

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

‎test/benchmark/test-benchmark-http.js‎

Lines changed: 3 additions & 0 deletions
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)