benchmark: move cli parts of common.js into run.js
It wasn't obviouse that common.js was the main cli tool. PR-URL: https://github.com/nodejs/node/pull/7094 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
edbed3f3fd
commit
0f9bfaa7c5
24
Makefile
24
Makefile
@ -627,41 +627,41 @@ ifneq ($(haswrk), 0)
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
bench-net: all
|
bench-net: all
|
||||||
@$(NODE) benchmark/common.js net
|
@$(NODE) benchmark/run.js net
|
||||||
|
|
||||||
bench-crypto: all
|
bench-crypto: all
|
||||||
@$(NODE) benchmark/common.js crypto
|
@$(NODE) benchmark/run.js crypto
|
||||||
|
|
||||||
bench-tls: all
|
bench-tls: all
|
||||||
@$(NODE) benchmark/common.js tls
|
@$(NODE) benchmark/run.js tls
|
||||||
|
|
||||||
bench-http: wrk all
|
bench-http: wrk all
|
||||||
@$(NODE) benchmark/common.js http
|
@$(NODE) benchmark/run.js http
|
||||||
|
|
||||||
bench-fs: all
|
bench-fs: all
|
||||||
@$(NODE) benchmark/common.js fs
|
@$(NODE) benchmark/run.js fs
|
||||||
|
|
||||||
bench-misc: all
|
bench-misc: all
|
||||||
@$(MAKE) -C benchmark/misc/function_call/
|
@$(MAKE) -C benchmark/misc/function_call/
|
||||||
@$(NODE) benchmark/common.js misc
|
@$(NODE) benchmark/run.js misc
|
||||||
|
|
||||||
bench-array: all
|
bench-array: all
|
||||||
@$(NODE) benchmark/common.js arrays
|
@$(NODE) benchmark/run.js arrays
|
||||||
|
|
||||||
bench-buffer: all
|
bench-buffer: all
|
||||||
@$(NODE) benchmark/common.js buffers
|
@$(NODE) benchmark/run.js buffers
|
||||||
|
|
||||||
bench-url: all
|
bench-url: all
|
||||||
@$(NODE) benchmark/common.js url
|
@$(NODE) benchmark/run.js url
|
||||||
|
|
||||||
bench-events: all
|
bench-events: all
|
||||||
@$(NODE) benchmark/common.js events
|
@$(NODE) benchmark/run.js events
|
||||||
|
|
||||||
bench-util: all
|
bench-util: all
|
||||||
@$(NODE) benchmark/common.js util
|
@$(NODE) benchmark/run.js util
|
||||||
|
|
||||||
bench-dgram: all
|
bench-dgram: all
|
||||||
@$(NODE) benchmark/common.js dgram
|
@$(NODE) benchmark/run.js dgram
|
||||||
|
|
||||||
bench-all: bench bench-misc bench-array bench-buffer bench-url bench-events bench-dgram bench-util
|
bench-all: bench bench-misc bench-array bench-buffer bench-url bench-events bench-dgram bench-util
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ There are three ways to run benchmark tests:
|
|||||||
For example, buffers:
|
For example, buffers:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
node benchmark/common.js buffers
|
node benchmark/run.js buffers
|
||||||
```
|
```
|
||||||
|
|
||||||
The above command will find all scripts under `buffers` directory and require
|
The above command will find all scripts under `buffers` directory and require
|
||||||
|
@ -15,35 +15,6 @@ if (['default', 'csv', 'silent'].indexOf(outputFormat) == -1) {
|
|||||||
|
|
||||||
exports.PORT = process.env.PORT || 12346;
|
exports.PORT = process.env.PORT || 12346;
|
||||||
|
|
||||||
// If this is the main module, then run the benchmarks
|
|
||||||
if (module === require.main) {
|
|
||||||
var type = process.argv[2];
|
|
||||||
var testFilter = process.argv[3];
|
|
||||||
if (!type) {
|
|
||||||
console.error('usage:\n ./node benchmark/common.js <type> [testFilter]');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
var dir = path.join(__dirname, type);
|
|
||||||
var tests = fs.readdirSync(dir);
|
|
||||||
|
|
||||||
if (testFilter) {
|
|
||||||
var filteredTests = tests.filter(function(item) {
|
|
||||||
if (item.lastIndexOf(testFilter) >= 0) {
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (filteredTests.length === 0) {
|
|
||||||
console.error('%s is not found in \n %j', testFilter, tests);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
tests = filteredTests;
|
|
||||||
}
|
|
||||||
|
|
||||||
runBenchmarks();
|
|
||||||
}
|
|
||||||
|
|
||||||
function hasWrk() {
|
function hasWrk() {
|
||||||
var result = child_process.spawnSync('wrk', ['-h']);
|
var result = child_process.spawnSync('wrk', ['-h']);
|
||||||
if (result.error && result.error.code === 'ENOENT') {
|
if (result.error && result.error.code === 'ENOENT') {
|
||||||
@ -53,31 +24,6 @@ function hasWrk() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function runBenchmarks() {
|
|
||||||
var test = tests.shift();
|
|
||||||
if (!test)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (test.match(/^[\._]/))
|
|
||||||
return process.nextTick(runBenchmarks);
|
|
||||||
|
|
||||||
if (outputFormat == 'default')
|
|
||||||
console.error(type + '/' + test);
|
|
||||||
|
|
||||||
test = path.resolve(dir, test);
|
|
||||||
|
|
||||||
var a = (process.execArgv || []).concat(test);
|
|
||||||
var child = child_process.spawn(process.execPath, a, { stdio: 'inherit' });
|
|
||||||
child.on('close', function(code) {
|
|
||||||
if (code) {
|
|
||||||
process.exit(code);
|
|
||||||
} else {
|
|
||||||
console.log('');
|
|
||||||
runBenchmarks();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.createBenchmark = function(fn, options) {
|
exports.createBenchmark = function(fn, options) {
|
||||||
return new Benchmark(fn, options);
|
return new Benchmark(fn, options);
|
||||||
};
|
};
|
||||||
@ -262,4 +208,3 @@ exports.v8ForceOptimization = function(method, ...args) {
|
|||||||
method.apply(null, args);
|
method.apply(null, args);
|
||||||
return eval('%GetOptimizationStatus(method)');
|
return eval('%GetOptimizationStatus(method)');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ function run() {
|
|||||||
if (Array.isArray(benchmarks) && benchmarks.length) {
|
if (Array.isArray(benchmarks) && benchmarks.length) {
|
||||||
child = spawn(
|
child = spawn(
|
||||||
node,
|
node,
|
||||||
['benchmark/common.js'].concat(benchmarks),
|
['benchmark/run.js'].concat(benchmarks),
|
||||||
{ env: env }
|
{ env: env }
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
63
benchmark/run.js
Normal file
63
benchmark/run.js
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const child_process = require('child_process');
|
||||||
|
|
||||||
|
var outputFormat = process.env.OUTPUT_FORMAT ||
|
||||||
|
(+process.env.NODE_BENCH_SILENT ? 'silent' : false) ||
|
||||||
|
'default';
|
||||||
|
|
||||||
|
// If this is the main module, then run the benchmarks
|
||||||
|
if (module === require.main) {
|
||||||
|
var type = process.argv[2];
|
||||||
|
var testFilter = process.argv[3];
|
||||||
|
if (!type) {
|
||||||
|
console.error('usage:\n ./node benchmark/run.js <type> [testFilter]');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
var dir = path.join(__dirname, type);
|
||||||
|
var tests = fs.readdirSync(dir);
|
||||||
|
|
||||||
|
if (testFilter) {
|
||||||
|
var filteredTests = tests.filter(function(item) {
|
||||||
|
if (item.lastIndexOf(testFilter) >= 0) {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (filteredTests.length === 0) {
|
||||||
|
console.error('%s is not found in \n %j', testFilter, tests);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tests = filteredTests;
|
||||||
|
}
|
||||||
|
|
||||||
|
runBenchmarks();
|
||||||
|
}
|
||||||
|
|
||||||
|
function runBenchmarks() {
|
||||||
|
var test = tests.shift();
|
||||||
|
if (!test)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (test.match(/^[\._]/))
|
||||||
|
return process.nextTick(runBenchmarks);
|
||||||
|
|
||||||
|
if (outputFormat == 'default')
|
||||||
|
console.error(type + '/' + test);
|
||||||
|
|
||||||
|
test = path.resolve(dir, test);
|
||||||
|
|
||||||
|
var a = (process.execArgv || []).concat(test);
|
||||||
|
var child = child_process.spawn(process.execPath, a, { stdio: 'inherit' });
|
||||||
|
child.on('close', function(code) {
|
||||||
|
if (code) {
|
||||||
|
process.exit(code);
|
||||||
|
} else {
|
||||||
|
console.log('');
|
||||||
|
runBenchmarks();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user