Skip to content

Commit

Permalink
benchmark: move cli parts of common.js into run.js
Browse files Browse the repository at this point in the history
It wasn't obviouse that common.js was the main cli tool.

PR-URL: #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]>
  • Loading branch information
AndreasMadsen committed Jul 26, 2016
1 parent edbed3f commit 0f9bfaa
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 69 deletions.
24 changes: 12 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 0 additions & 55 deletions benchmark/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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);
};
Expand Down Expand Up @@ -262,4 +208,3 @@ exports.v8ForceOptimization = function(method, ...args) {
method.apply(null, args);
return eval('%GetOptimizationStatus(method)');
};

2 changes: 1 addition & 1 deletion benchmark/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
63 changes: 63 additions & 0 deletions benchmark/run.js
Original file line number Diff line number Diff line change
@@ -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.