Skip to content

Commit f4955fd

Browse files
refackrvagg
authored andcommitted
benchmark,test: refactoring
PR-URL: #26119 Refs: #26101 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 38a87d5 commit f4955fd

File tree

4 files changed

+47
-41
lines changed

4 files changed

+47
-41
lines changed
Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
'use strict';
22

33
constcommon=require('../common.js');
4-
constClientRequest=require('http').ClientRequest;
4+
const{ ClientRequest }=require('http');
5+
constassert=require('assert');
6+
57
consttypes=Object.keys(common.urls)
68
.filter((i)=>common.urls[i]
79
.startsWith('http://'));
@@ -15,36 +17,43 @@ const bench = common.createBenchmark(main,{
1517
functionnoop(){}
1618

1719
functionmain({url: type, arg, e }){
18-
e=+e;
20+
e=Number(e);
1921
constdata=common.bakeUrlData(type,e,false,false)
2022
.filter((i)=>i.startsWith('http://'));
2123
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]);
24+
letresult;
25+
switch(arg){
26+
case'options': {
27+
constoptions=data.map((i)=>({
28+
path: newURL(i).path,createConnection: noop
29+
}));
30+
bench.start();
31+
for(leti=0;i<len;i++){
32+
result=newClientRequest(options[i]);
33+
}
34+
bench.end(len);
35+
break;
36+
}
37+
case'URL': {
38+
constoptions=data.map((i)=>newURL(i));
39+
bench.start();
40+
for(leti=0;i<len;i++){
41+
result=newClientRequest(options[i],{createConnection: noop});
42+
}
43+
bench.end(len);
44+
break;
3145
}
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});
46+
case'string': {
47+
bench.start();
48+
for(leti=0;i<len;i++){
49+
result=newClientRequest(data[i],{createConnection: noop});
50+
}
51+
bench.end(len);
52+
break;
3853
}
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});
54+
default: {
55+
thrownewError(`Unknown arg type ${arg}`);
4456
}
45-
bench.end(len);
46-
}else{
47-
thrownewError(`Unknown arg type ${arg}`);
4857
}
49-
require('assert').ok(result);
58+
assert.ok(result);
5059
}

‎benchmark/http/headers.js‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ const common = require('../common.js');
44
consthttp=require('http');
55

66
constbench=common.createBenchmark(main,{
7-
duplicates: [1,100],
87
n: [10,1000],
8+
len: [1,100],
99
});
1010

11-
functionmain({duplicates, n }){
11+
functionmain({len, n }){
1212
constheaders={
1313
'Connection': 'keep-alive',
1414
'Transfer-Encoding': 'chunked',
1515
};
1616

17-
for(vari=0;i<n/duplicates;i++){
18-
headers[`foo${i}`]=[];
19-
for(varj=0;j<duplicates;j++){
20-
headers[`foo${i}`].push(`some header value ${i}`);
21-
}
17+
constIs=[ ...Array(n/len).keys()];
18+
constJs=[ ...Array(len).keys()];
19+
for(constiofIs){
20+
headers[`foo${i}`]=Js.map(()=>`some header value ${i}`);
2221
}
2322

2423
constserver=http.createServer((req,res)=>{

‎benchmark/http/incoming_headers.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ const http = require('http');
55
constbench=common.createBenchmark(main,{
66
// unicode confuses ab on os x.
77
c: [50,500],
8-
headerDuplicates: [0,5,20]
8+
n: [0,5,20]
99
});
1010

11-
functionmain({ c,headerDuplicates}){
11+
functionmain({ c,n}){
1212
constserver=http.createServer((req,res)=>{
1313
res.end();
1414
});
@@ -21,7 +21,7 @@ function main({c, headerDuplicates }){
2121
'Date': newDate().toString(),
2222
'Cache-Control': 'no-cache'
2323
};
24-
for(leti=0;i<headerDuplicates;i++){
24+
for(leti=0;i<n;i++){
2525
headers[`foo${i}`]=`some header value ${i}`;
2626
}
2727
bench.http({

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,21 @@ const runBenchmark = require('../common/benchmark');
1414
runBenchmark('http',
1515
[
1616
'benchmarker=test-double-http',
17-
'c=1',
18-
'e=0',
19-
'url=long',
2017
'arg=string',
18+
'c=1',
2119
'chunkedEnc=true',
2220
'chunks=0',
2321
'dur=0.1',
24-
'duplicates=1',
22+
'e=0',
2523
'input=keep-alive',
2624
'key=""',
2725
'len=1',
2826
'method=write',
2927
'n=1',
3028
'res=normal',
3129
'type=asc',
30+
'url=long',
3231
'value=X-Powered-By',
33-
'headerDuplicates=1',
3432
],
3533
{
3634
NODEJS_BENCHMARK_ZERO_ALLOWED: 1,

0 commit comments

Comments
(0)