Permalink
Browse files

benchmark: move cli parts of common.js into run.js

It wasn't obviouse that common.js was the main cli tool.

PR-URL: #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>
  • Loading branch information...
AndreasMadsen committed Jan 30, 2016
1 parent edbed3f commit 0f9bfaa7c51bb5f4910ddf068ed89b1bdf35e7d5
Showing with 77 additions and 69 deletions.
  1. +12 −12 Makefile
  2. +1 −1 benchmark/README.md
  3. +0 −55 benchmark/common.js
  4. +1 −1 benchmark/compare.js
  5. +63 −0 benchmark/run.js
@@ -627,41 +627,41 @@ ifneq ($(haswrk), 0)
endif
bench-net: all
@$(NODE) benchmark/common.js net
@$(NODE) benchmark/run.js net
bench-crypto: all
@$(NODE) benchmark/common.js crypto
@$(NODE) benchmark/run.js crypto
bench-tls: all
@$(NODE) benchmark/common.js tls
@$(NODE) benchmark/run.js tls
bench-http: wrk all
@$(NODE) benchmark/common.js http
@$(NODE) benchmark/run.js http
bench-fs: all
@$(NODE) benchmark/common.js fs
@$(NODE) benchmark/run.js fs
bench-misc: all
@$(MAKE) -C benchmark/misc/function_call/
@$(NODE) benchmark/common.js misc
@$(NODE) benchmark/run.js misc
bench-array: all
@$(NODE) benchmark/common.js arrays
@$(NODE) benchmark/run.js arrays
bench-buffer: all
@$(NODE) benchmark/common.js buffers
@$(NODE) benchmark/run.js buffers
bench-url: all
@$(NODE) benchmark/common.js url
@$(NODE) benchmark/run.js url
bench-events: all
@$(NODE) benchmark/common.js events
@$(NODE) benchmark/run.js events
bench-util: all
@$(NODE) benchmark/common.js util
@$(NODE) benchmark/run.js util
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
@@ -24,7 +24,7 @@ There are three ways to run benchmark tests:
For example, buffers:
```bash
node benchmark/common.js buffers
node benchmark/run.js buffers
```
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;
// 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() {
var result = child_process.spawnSync('wrk', ['-h']);
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) {
return new Benchmark(fn, options);
};
@@ -262,4 +208,3 @@ exports.v8ForceOptimization = function(method, ...args) {
method.apply(null, args);
return eval('%GetOptimizationStatus(method)');
};
@@ -80,7 +80,7 @@ function run() {
if (Array.isArray(benchmarks) && benchmarks.length) {
child = spawn(
node,
['benchmark/common.js'].concat(benchmarks),
['benchmark/run.js'].concat(benchmarks),
{ env: env }
);
} else {
@@ -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();
}
});
}

0 comments on commit 0f9bfaa

Please sign in to comment.