0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/benchmark/run.js
Andreas Madsen f99471b2ae 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>
2016-07-26 13:21:39 +02:00

52 lines
1.3 KiB
JavaScript

'use strict';
const path = require('path');
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 recursive(i) {
const filename = benchmarks[i];
const child = fork(path.resolve(__dirname, filename), cli.optional.set);
console.log();
console.log(filename);
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]);
}
console.log(`${data.name}${conf}: ${data.rate}`);
});
child.once('close', function(code) {
if (code) {
process.exit(code);
return;
}
// If there are more benchmarks execute the next
if (i + 1 < benchmarks.length) {
recursive(i + 1);
}
});
})(0);