Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Madsen <amwebdk@gmail.com>2016-02-01 13:30:00 +0300
committerAndreas Madsen <amwebdk@gmail.com>2016-07-26 14:21:39 +0300
commitf99471b2ae147fbb072223be62e9100862379dc8 (patch)
tree9ba2bd15230ccbd74a55f1c98dceb7e72ce76426 /benchmark/run.js
parent0f9bfaa7c51bb5f4910ddf068ed89b1bdf35e7d5 (diff)
benchmark: refactor to use process.send
This removes the need for parsing stdout from the benchmarks. If the process wasn't executed by fork, it will just print like it used to. This also fixes the parsing of CLI arguments, by inferring the type from the options object instead of the value content. Only two benchmarks had to be changed: * http/http_server_for_chunky_client.js this previously used a spawn now it uses a fork and relays the messages using common.sendResult. * misc/v8-bench.js this utilized that v8/benchmark/run.js called global.print and reformatted the input. It now interfaces directly with the benchmark runner global.BenchmarkSuite. 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>
Diffstat (limited to 'benchmark/run.js')
-rw-r--r--benchmark/run.js88
1 files changed, 38 insertions, 50 deletions
diff --git a/benchmark/run.js b/benchmark/run.js
index ad590ea34a8..756a7408bbb 100644
--- a/benchmark/run.js
+++ b/benchmark/run.js
@@ -1,63 +1,51 @@
'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();
+const fork = require('child_process').fork;
+const CLI = require('./_cli.js');
+
+const cli = CLI(`usage: ./node run.js [options] [--] <category> ...
+ Run each benchmark in the <category> directory a single time, more than one
+ <categoty> directory can be specified.
+
+ --filter pattern string to filter benchmark scripts
+ --set variable=value set benchmark variable (can be repeated)
+`, {
+ arrayArgs: ['set']
+});
+const benchmarks = cli.benchmarks();
+
+if (benchmarks.length === 0) {
+ console.error('no benchmarks found');
+ process.exit(1);
}
-function runBenchmarks() {
- var test = tests.shift();
- if (!test)
- return;
+(function recursive(i) {
+ const filename = benchmarks[i];
+ const child = fork(path.resolve(__dirname, filename), cli.optional.set);
- if (test.match(/^[\._]/))
- return process.nextTick(runBenchmarks);
+ console.log();
+ console.log(filename);
- if (outputFormat == 'default')
- console.error(type + '/' + test);
+ child.on('message', function(data) {
+ // Construct configuration string, " A=a, B=b, ..."
+ let conf = '';
+ for (const key of Object.keys(data.conf)) {
+ conf += ' ' + key + '=' + JSON.stringify(data.conf[key]);
+ }
- test = path.resolve(dir, test);
+ console.log(`${data.name}${conf}: ${data.rate}`);
+ });
- var a = (process.execArgv || []).concat(test);
- var child = child_process.spawn(process.execPath, a, { stdio: 'inherit' });
- child.on('close', function(code) {
+ child.once('close', function(code) {
if (code) {
process.exit(code);
- } else {
- console.log('');
- runBenchmarks();
+ return;
+ }
+
+ // If there are more benchmarks execute the next
+ if (i + 1 < benchmarks.length) {
+ recursive(i + 1);
}
});
-}
+})(0);