aboutsummaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorAdrian Nitu <adrian.nitu@intel.com>2016-08-03 14:40:53 +0300
committerAndreas Madsen <amwebdk@gmail.com>2016-08-12 13:23:43 +0200
commit474e629ddbd7706d9ce00b2f4b631b98ee17d988 (patch)
tree0f691b8a7cfab9b2e0b135ecb7073fdafdc3e9ac /benchmark
parent4b527a4129c00531ff852c78cd20e480120e65bd (diff)
downloadandroid-node-v8-474e629ddbd7706d9ce00b2f4b631b98ee17d988.tar.gz
android-node-v8-474e629ddbd7706d9ce00b2f4b631b98ee17d988.tar.bz2
android-node-v8-474e629ddbd7706d9ce00b2f4b631b98ee17d988.zip
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>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/run.js35
1 files changed, 29 insertions, 6 deletions
diff --git a/benchmark/run.js b/benchmark/run.js
index 756a7408bb..16e620f9a0 100644
--- a/benchmark/run.js
+++ b/benchmark/run.js
@@ -10,22 +10,38 @@ const cli = CLI(`usage: ./node run.js [options] [--] <category> ...
--filter pattern string to filter benchmark scripts
--set variable=value set benchmark variable (can be repeated)
+ --format [simple|csv] optional value that specifies the output format
`, {
arrayArgs: ['set']
});
const benchmarks = cli.benchmarks();
if (benchmarks.length === 0) {
- console.error('no benchmarks found');
- process.exit(1);
+ console.error('No benchmarks found');
+ 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) {
const filename = benchmarks[i];
const child = fork(path.resolve(__dirname, filename), cli.optional.set);
- console.log();
- console.log(filename);
+ if (format !== 'csv') {
+ console.log();
+ console.log(filename);
+ }
child.on('message', function(data) {
// Construct configuration string, " A=a, B=b, ..."
@@ -33,8 +49,15 @@ if (benchmarks.length === 0) {
for (const key of Object.keys(data.conf)) {
conf += ' ' + key + '=' + JSON.stringify(data.conf[key]);
}
-
- console.log(`${data.name}${conf}: ${data.rate}`);
+ // delete first space of the configuration
+ 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) {