Skip to content

Commit 0f9bfaa

Browse files
committed
benchmark: move cli parts of common.js into run.js
It wasn't obviouse that common.js was the main cli tool. PR-URL: nodejs#7094 Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Brian White <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent edbed3f commit 0f9bfaa

File tree

5 files changed

+77
-69
lines changed

5 files changed

+77
-69
lines changed

Makefile

+12-12
Original file line numberDiff line numberDiff line change
@@ -627,41 +627,41 @@ ifneq ($(haswrk), 0)
627627
endif
628628

629629
bench-net: all
630-
@$(NODE) benchmark/common.js net
630+
@$(NODE) benchmark/run.js net
631631

632632
bench-crypto: all
633-
@$(NODE) benchmark/common.js crypto
633+
@$(NODE) benchmark/run.js crypto
634634

635635
bench-tls: all
636-
@$(NODE) benchmark/common.js tls
636+
@$(NODE) benchmark/run.js tls
637637

638638
bench-http: wrk all
639-
@$(NODE) benchmark/common.js http
639+
@$(NODE) benchmark/run.js http
640640

641641
bench-fs: all
642-
@$(NODE) benchmark/common.js fs
642+
@$(NODE) benchmark/run.js fs
643643

644644
bench-misc: all
645645
@$(MAKE) -C benchmark/misc/function_call/
646-
@$(NODE) benchmark/common.js misc
646+
@$(NODE) benchmark/run.js misc
647647

648648
bench-array: all
649-
@$(NODE) benchmark/common.js arrays
649+
@$(NODE) benchmark/run.js arrays
650650

651651
bench-buffer: all
652-
@$(NODE) benchmark/common.js buffers
652+
@$(NODE) benchmark/run.js buffers
653653

654654
bench-url: all
655-
@$(NODE) benchmark/common.js url
655+
@$(NODE) benchmark/run.js url
656656

657657
bench-events: all
658-
@$(NODE) benchmark/common.js events
658+
@$(NODE) benchmark/run.js events
659659

660660
bench-util: all
661-
@$(NODE) benchmark/common.js util
661+
@$(NODE) benchmark/run.js util
662662

663663
bench-dgram: all
664-
@$(NODE) benchmark/common.js dgram
664+
@$(NODE) benchmark/run.js dgram
665665

666666
bench-all: bench bench-misc bench-array bench-buffer bench-url bench-events bench-dgram bench-util
667667

benchmark/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ There are three ways to run benchmark tests:
2424
For example, buffers:
2525

2626
```bash
27-
node benchmark/common.js buffers
27+
node benchmark/run.js buffers
2828
```
2929

3030
The above command will find all scripts under `buffers` directory and require

benchmark/common.js

-55
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,6 @@ if (['default', 'csv', 'silent'].indexOf(outputFormat) == -1) {
1515

1616
exports.PORT = process.env.PORT || 12346;
1717

18-
// If this is the main module, then run the benchmarks
19-
if (module === require.main) {
20-
var type = process.argv[2];
21-
var testFilter = process.argv[3];
22-
if (!type) {
23-
console.error('usage:\n ./node benchmark/common.js <type> [testFilter]');
24-
process.exit(1);
25-
}
26-
27-
var dir = path.join(__dirname, type);
28-
var tests = fs.readdirSync(dir);
29-
30-
if (testFilter) {
31-
var filteredTests = tests.filter(function(item) {
32-
if (item.lastIndexOf(testFilter) >= 0) {
33-
return item;
34-
}
35-
});
36-
37-
if (filteredTests.length === 0) {
38-
console.error('%s is not found in \n %j', testFilter, tests);
39-
return;
40-
}
41-
tests = filteredTests;
42-
}
43-
44-
runBenchmarks();
45-
}
46-
4718
function hasWrk() {
4819
var result = child_process.spawnSync('wrk', ['-h']);
4920
if (result.error && result.error.code === 'ENOENT') {
@@ -53,31 +24,6 @@ function hasWrk() {
5324
}
5425
}
5526

56-
function runBenchmarks() {
57-
var test = tests.shift();
58-
if (!test)
59-
return;
60-
61-
if (test.match(/^[\._]/))
62-
return process.nextTick(runBenchmarks);
63-
64-
if (outputFormat == 'default')
65-
console.error(type + '/' + test);
66-
67-
test = path.resolve(dir, test);
68-
69-
var a = (process.execArgv || []).concat(test);
70-
var child = child_process.spawn(process.execPath, a, { stdio: 'inherit' });
71-
child.on('close', function(code) {
72-
if (code) {
73-
process.exit(code);
74-
} else {
75-
console.log('');
76-
runBenchmarks();
77-
}
78-
});
79-
}
80-
8127
exports.createBenchmark = function(fn, options) {
8228
return new Benchmark(fn, options);
8329
};
@@ -262,4 +208,3 @@ exports.v8ForceOptimization = function(method, ...args) {
262208
method.apply(null, args);
263209
return eval('%GetOptimizationStatus(method)');
264210
};
265-

benchmark/compare.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function run() {
8080
if (Array.isArray(benchmarks) && benchmarks.length) {
8181
child = spawn(
8282
node,
83-
['benchmark/common.js'].concat(benchmarks),
83+
['benchmark/run.js'].concat(benchmarks),
8484
{ env: env }
8585
);
8686
} else {

benchmark/run.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
const child_process = require('child_process');
6+
7+
var outputFormat = process.env.OUTPUT_FORMAT ||
8+
(+process.env.NODE_BENCH_SILENT ? 'silent' : false) ||
9+
'default';
10+
11+
// If this is the main module, then run the benchmarks
12+
if (module === require.main) {
13+
var type = process.argv[2];
14+
var testFilter = process.argv[3];
15+
if (!type) {
16+
console.error('usage:\n ./node benchmark/run.js <type> [testFilter]');
17+
process.exit(1);
18+
}
19+
20+
var dir = path.join(__dirname, type);
21+
var tests = fs.readdirSync(dir);
22+
23+
if (testFilter) {
24+
var filteredTests = tests.filter(function(item) {
25+
if (item.lastIndexOf(testFilter) >= 0) {
26+
return item;
27+
}
28+
});
29+
30+
if (filteredTests.length === 0) {
31+
console.error('%s is not found in \n %j', testFilter, tests);
32+
return;
33+
}
34+
tests = filteredTests;
35+
}
36+
37+
runBenchmarks();
38+
}
39+
40+
function runBenchmarks() {
41+
var test = tests.shift();
42+
if (!test)
43+
return;
44+
45+
if (test.match(/^[\._]/))
46+
return process.nextTick(runBenchmarks);
47+
48+
if (outputFormat == 'default')
49+
console.error(type + '/' + test);
50+
51+
test = path.resolve(dir, test);
52+
53+
var a = (process.execArgv || []).concat(test);
54+
var child = child_process.spawn(process.execPath, a, { stdio: 'inherit' });
55+
child.on('close', function(code) {
56+
if (code) {
57+
process.exit(code);
58+
} else {
59+
console.log('');
60+
runBenchmarks();
61+
}
62+
});
63+
}

0 commit comments

Comments
 (0)