From 032b8728d103d29e9ed9a035d3a8c6d08900f471 Mon Sep 17 00:00:00 2001 From: Adrian Nitu Date: Thu, 4 Aug 2016 12:00:59 +0300 Subject: [PATCH 1/3] benchmark: fix comment typos and code format I noticed some typos and the lack of {} following an if. Signed-off-by: Adrian Nitu --- benchmark/common.js | 10 +++++----- benchmark/compare.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/benchmark/common.js b/benchmark/common.js index 669a4c642b2bfd..3807fea7957096 100644 --- a/benchmark/common.js +++ b/benchmark/common.js @@ -30,7 +30,7 @@ function Benchmark(fn, options) { Benchmark.prototype._parseArgs = function(argv, options) { const cliOptions = Object.assign({}, options); - // Parse configuarion arguments + // Parse configuration arguments for (const arg of argv) { const match = arg.match(/^(.+?)=([\s\S]*)$/); if (!match || !match[1]) { @@ -52,7 +52,7 @@ Benchmark.prototype._queue = function(options) { const queue = []; const keys = Object.keys(options); - // Perform a depth-first walk though all options to genereate a + // Perform a depth-first walk though all options to generate a // configuration list that contains all combinations. function recursive(keyIndex, prevConfig) { const key = keys[keyIndex]; @@ -171,9 +171,9 @@ Benchmark.prototype._run = function() { }; Benchmark.prototype.start = function() { - if (this._started) + if (this._started) { throw new Error('Called start more than once in a single benchmark'); - + } this._started = true; this._time = process.hrtime(); }; @@ -195,7 +195,7 @@ Benchmark.prototype.end = function(operations) { }; function formatResult(data) { - // Construct confiuration string, " A=a, B=b, ..." + // Construct configuration string, " A=a, B=b, ..." let conf = ''; for (const key of Object.keys(data.conf)) { conf += ' ' + key + '=' + JSON.stringify(data.conf[key]); diff --git a/benchmark/compare.js b/benchmark/compare.js index fb179e0e4703ed..94ff19bb56701a 100644 --- a/benchmark/compare.js +++ b/benchmark/compare.js @@ -65,7 +65,7 @@ console.log('"binary", "filename", "configuration", "rate", "time"'); } conf = conf.slice(1); - // Escape qoutes (") for correct csv formatting + // Escape quotes (") for correct csv formatting conf = conf.replace(/"/g, '""'); console.log(`"${job.binary}", "${job.filename}", "${conf}", ` + From 5b64f9b1db2c51723f04bb5b56bf73b085f7144a Mon Sep 17 00:00:00 2001 From: Adrian Nitu Date: Fri, 5 Aug 2016 13:17:41 +0300 Subject: [PATCH 2/3] benchmark: update compare.js exit method Node documentation recommends using process.exitCode = x and returning as a way to exit. Signed-off-by: Adrian Nitu --- benchmark/compare.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/benchmark/compare.js b/benchmark/compare.js index 94ff19bb56701a..de328d60fcbae0 100644 --- a/benchmark/compare.js +++ b/benchmark/compare.js @@ -33,7 +33,8 @@ const benchmarks = cli.benchmarks(); if (benchmarks.length === 0) { console.error('no benchmarks found'); - process.exit(1); + process.exitCode = 1; + return; } // Create queue from the benchmarks list such both node versions are tested From fbcd137926aef07c55ee82086b871c9d6947b491 Mon Sep 17 00:00:00 2001 From: Adrian Nitu Date: Wed, 3 Aug 2016 14:40:53 +0300 Subject: [PATCH 3/3] benchmark: add --format csv option Added the option of using --format csv when outputting data. Signed-off-by: Adrian Nitu --- benchmark/run.js | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/benchmark/run.js b/benchmark/run.js index 756a7408bbbf37..16e620f9a0db7b 100644 --- a/benchmark/run.js +++ b/benchmark/run.js @@ -10,22 +10,38 @@ const cli = CLI(`usage: ./node run.js [options] [--] ... --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) {