Skip to content

Commit 8974fa7

Browse files
addaleaxcodebytere
authored andcommitted
Revert "benchmark: add test and all options and improve errors"
This reverts commit dac5795. Refs: #31396 PR-URL: #31722 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 5b3c4b3 commit 8974fa7

37 files changed

Lines changed: 189 additions & 292 deletions

‎benchmark/_cli.js‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,22 @@ const path = require('path');
66
// Create an object of all benchmark scripts
77
constbenchmarks={};
88
fs.readdirSync(__dirname)
9-
.filter((name)=>{
10-
returnname!=='fixtures'&&
11-
fs.statSync(path.resolve(__dirname,name)).isDirectory();
12-
})
9+
.filter((name)=>fs.statSync(path.resolve(__dirname,name)).isDirectory())
1310
.forEach((category)=>{
1411
benchmarks[category]=fs.readdirSync(path.resolve(__dirname,category))
1512
.filter((filename)=>filename[0]!=='.'&&filename[0]!=='_');
1613
});
1714

1815
functionCLI(usage,settings){
16+
if(!(thisinstanceofCLI))returnnewCLI(usage,settings);
17+
1918
if(process.argv.length<3){
2019
this.abort(usage);// Abort will exit the process
2120
}
2221

2322
this.usage=usage;
2423
this.optional={};
2524
this.items=[];
26-
this.test=false;
2725

2826
for(constargNameofsettings.arrayArgs){
2927
this.optional[argName]=[];
@@ -36,7 +34,7 @@ function CLI(usage, settings) {
3634
if(arg==='--'){
3735
// Only items can follow --
3836
mode='item';
39-
}elseif(mode==='both'&&arg[0]==='-'){
37+
}elseif('both'===mode&&arg[0]==='-'){
4038
// Optional arguments declaration
4139

4240
if(arg[1]==='-'){
@@ -63,8 +61,6 @@ function CLI(usage, settings) {
6361

6462
// The next value can be either an option or an item
6563
mode='both';
66-
}elseif(arg==='test'){
67-
this.test=true;
6864
}elseif(['both','item'].includes(mode)){
6965
// item arguments
7066
this.items.push(arg);
@@ -87,15 +83,9 @@ CLI.prototype.abort = function(msg) {
8783
CLI.prototype.benchmarks=function(){
8884
constpaths=[];
8985

90-
if(this.items.includes('all')){
91-
this.items=Object.keys(benchmarks);
92-
}
93-
9486
for(constcategoryofthis.items){
95-
if(benchmarks[category]===undefined){
96-
console.error(`The "${category}" category does not exist.`);
97-
process.exit(1);
98-
}
87+
if(benchmarks[category]===undefined)
88+
continue;
9989
for(constscriptsofbenchmarks[category]){
10090
if(this.shouldSkip(scripts))continue;
10191

‎benchmark/_http-benchmarkers.js‎

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ class AutocannonBenchmarker {
4343
}
4444
if(!result||!result.requests||!result.requests.average){
4545
returnundefined;
46+
}else{
47+
returnresult.requests.average;
4648
}
47-
returnresult.requests.average;
4849
}
4950
}
5051

@@ -76,8 +77,9 @@ class WrkBenchmarker {
7677
constthroughput=match&&+match[1];
7778
if(!isFinite(throughput)){
7879
returnundefined;
80+
}else{
81+
returnthroughput;
7982
}
80-
returnthroughput;
8183
}
8284
}
8385

@@ -87,20 +89,18 @@ class WrkBenchmarker {
8789
*/
8890
classTestDoubleBenchmarker{
8991
constructor(type){
90-
// `type` is the type of benchmarker. Possible values are 'http' and
91-
// 'http2'.
92+
// `type` is the type ofbenchmarker. Possible values are 'http' and 'http2'.
9293
this.name=`test-double-${type}`;
9394
this.executable=path.resolve(__dirname,'_test-double-benchmarker.js');
9495
this.present=fs.existsSync(this.executable);
9596
this.type=type;
9697
}
9798

9899
create(options){
99-
constenv={
100+
constenv=Object.assign({
100101
duration: options.duration,
101102
test_url: `http://127.0.0.1:${options.port}${options.path}`,
102-
...process.env
103-
};
103+
},process.env);
104104

105105
constchild=child_process.fork(this.executable,
106106
[this.type],
@@ -189,14 +189,13 @@ http_benchmarkers.forEach((benchmarker) => {
189189
});
190190

191191
exports.run=function(options,callback){
192-
options={
192+
options=Object.assign({
193193
port: exports.PORT,
194194
path: '/',
195195
connections: 100,
196196
duration: 5,
197197
benchmarker: exports.default_http_benchmarker,
198-
...options
199-
};
198+
},options);
200199
if(!options.benchmarker){
201200
callback(newError('Could not locate required http benchmarker. See '+
202201
`${requirementsURL} for further instructions.`));
@@ -213,7 +212,6 @@ exports.run = function(options, callback) {
213212
'is not installed'));
214213
return;
215214
}
216-
process.env.duration=process.env.duration||options.duration||5;
217215

218216
constbenchmarker_start=process.hrtime();
219217

@@ -222,8 +220,7 @@ exports.run = function(options, callback) {
222220
child.stderr.pipe(process.stderr);
223221

224222
letstdout='';
225-
child.stdout.setEncoding('utf8');
226-
child.stdout.on('data',(chunk)=>stdout+=chunk);
223+
child.stdout.on('data',(chunk)=>stdout+=chunk.toString());
227224

228225
child.once('close',(code)=>{
229226
constelapsed=process.hrtime(benchmarker_start);

‎benchmark/_test-double-benchmarker.js‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if (!['http', 'http2'].includes(myModule)) {
77

88
consthttp=require(myModule);
99

10-
constduration=+process.env.duration;
10+
constduration=process.env.duration||0;
1111
consturl=process.env.test_url;
1212

1313
conststart=process.hrtime();
@@ -18,15 +18,13 @@ function request(res, client) {
1818
res.on('error',()=>{});
1919
res.on('end',()=>{
2020
throughput++;
21-
const[sec,nanosec]=process.hrtime(start);
22-
constms=sec*1000+nanosec/1e6;
23-
if(ms<duration*1000){
21+
constdiff=process.hrtime(start);
22+
if(duration>0&&diff[0]<duration){
2423
run();
2524
}else{
2625
console.log(JSON.stringify({ throughput }));
2726
if(client){
2827
client.destroy();
29-
process.exit(0);
3028
}
3129
}
3230
});
@@ -35,7 +33,7 @@ function request(res, client) {
3533
functionrun(){
3634
if(http.get){// HTTP
3735
http.get(url,request);
38-
}else{// HTTP/2
36+
}else{// HTTP/2
3937
constclient=http.connect(url);
4038
client.on('error',(e)=>{throwe;});
4139
request(client.request(),client);

‎benchmark/async_hooks/http-server.js‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ const common = require('../common.js');
33

44
constbench=common.createBenchmark(main,{
55
asyncHooks: ['init','before','after','all','disabled','none'],
6-
connections: [50,500],
7-
duration: 5
6+
connections: [50,500]
87
});
98

10-
functionmain({ asyncHooks, connections, duration}){
9+
functionmain({ asyncHooks, connections }){
1110
if(asyncHooks!=='none'){
1211
lethooks={
1312
init(){},
@@ -34,7 +33,6 @@ function main({ asyncHooks, connections, duration }) {
3433
bench.http({
3534
connections,
3635
path,
37-
duration
3836
},()=>{
3937
server.close();
4038
});

‎benchmark/buffers/buffer-base64-encode.js‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ const common = require('../common.js');
2525
constbench=common.createBenchmark(main,{
2626
len: [64*1024*1024],
2727
n: [32]
28-
},{
29-
test: {len: 256}
3028
});
3129

3230
functionmain({ n, len }){

‎benchmark/buffers/buffer-swap.js‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ const bench = common.createBenchmark(main, {
77
method: ['swap16','swap32','swap64'/* , 'htons', 'htonl', 'htonll' */],
88
len: [64,256,768,1024,2056,8192],
99
n: [1e6]
10-
},{
11-
test: {len: 16}
1210
});
1311

1412
// The htons and htonl methods below are used to benchmark the

0 commit comments

Comments
 (0)