benchmark: add --format csv option
Added the option of using --format csv when outputting data. Fixes: https://github.com/nodejs/node/issues/7890 PR-URL: https://github.com/nodejs/node/pull/7961 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
This commit is contained in:
parent
4b527a4129
commit
474e629ddb
@ -10,22 +10,38 @@ const cli = CLI(`usage: ./node run.js [options] [--] <category> ...
|
|||||||
|
|
||||||
--filter pattern string to filter benchmark scripts
|
--filter pattern string to filter benchmark scripts
|
||||||
--set variable=value set benchmark variable (can be repeated)
|
--set variable=value set benchmark variable (can be repeated)
|
||||||
|
--format [simple|csv] optional value that specifies the output format
|
||||||
`, {
|
`, {
|
||||||
arrayArgs: ['set']
|
arrayArgs: ['set']
|
||||||
});
|
});
|
||||||
const benchmarks = cli.benchmarks();
|
const benchmarks = cli.benchmarks();
|
||||||
|
|
||||||
if (benchmarks.length === 0) {
|
if (benchmarks.length === 0) {
|
||||||
console.error('no benchmarks found');
|
console.error('No benchmarks found');
|
||||||
process.exit(1);
|
process.exitCode = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const validFormats = ['csv', 'simple'];
|
||||||
|
const format = cli.optional.format || 'simple';
|
||||||
|
if (!validFormats.includes(format)) {
|
||||||
|
console.error('Invalid format detected');
|
||||||
|
process.exitCode = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (format === 'csv') {
|
||||||
|
console.log('"filename", "configuration", "rate", "time"');
|
||||||
}
|
}
|
||||||
|
|
||||||
(function recursive(i) {
|
(function recursive(i) {
|
||||||
const filename = benchmarks[i];
|
const filename = benchmarks[i];
|
||||||
const child = fork(path.resolve(__dirname, filename), cli.optional.set);
|
const child = fork(path.resolve(__dirname, filename), cli.optional.set);
|
||||||
|
|
||||||
console.log();
|
if (format !== 'csv') {
|
||||||
console.log(filename);
|
console.log();
|
||||||
|
console.log(filename);
|
||||||
|
}
|
||||||
|
|
||||||
child.on('message', function(data) {
|
child.on('message', function(data) {
|
||||||
// Construct configuration string, " A=a, B=b, ..."
|
// Construct configuration string, " A=a, B=b, ..."
|
||||||
@ -33,8 +49,15 @@ if (benchmarks.length === 0) {
|
|||||||
for (const key of Object.keys(data.conf)) {
|
for (const key of Object.keys(data.conf)) {
|
||||||
conf += ' ' + key + '=' + JSON.stringify(data.conf[key]);
|
conf += ' ' + key + '=' + JSON.stringify(data.conf[key]);
|
||||||
}
|
}
|
||||||
|
// delete first space of the configuration
|
||||||
console.log(`${data.name}${conf}: ${data.rate}`);
|
conf = conf.slice(1);
|
||||||
|
if (format === 'csv') {
|
||||||
|
// Escape quotes (") for correct csv formatting
|
||||||
|
conf = conf.replace(/"/g, '""');
|
||||||
|
console.log(`"${data.name}", "${conf}", ${data.rate}, ${data.time}`);
|
||||||
|
} else {
|
||||||
|
console.log(`${data.name} ${conf}: ${data.rate}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
child.once('close', function(code) {
|
child.once('close', function(code) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user