From c638dad56775c9593d1d79b7f9f79c49bbcd9628 Mon Sep 17 00:00:00 2001 From: Brendan Ashworth Date: Mon, 9 Feb 2015 19:36:52 -0800 Subject: [PATCH] benchmark: add output format option [csv] This commit adds an `OUTPUT_FORMAT` environment variable option for all benchmark tests that allow either 'csv' or 'default' output. Default output has been left unchanged, and csv output prints out the csv headers along with the csv formatted per-test output, each test also seperated by a newline. It can be used like the following: $ OUTPUT_FORMAT=csv iojs benchmark/common.js http Not specifying the OUTPUT_FORMAT env var will default to 'default'. Specifying a bad value will throw an error. PR-URL: https://github.com/iojs/io.js/pull/777 Reviewed-By: Ben Noordhuis --- benchmark/common.js | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/benchmark/common.js b/benchmark/common.js index 2a518745bd..199d9a54f5 100644 --- a/benchmark/common.js +++ b/benchmark/common.js @@ -3,7 +3,14 @@ var fs = require('fs'); var path = require('path'); var child_process = require('child_process'); -var silent = +process.env.NODE_BENCH_SILENT; +var outputFormat = process.env.OUTPUT_FORMAT || + (+process.env.NODE_BENCH_SILENT ? 'silent' : false) || + 'default'; + +// verify outputFormat +if (['default', 'csv', 'silent'].indexOf(outputFormat) == -1) { + throw new Error('OUTPUT_FORMAT set to invalid value'); +} exports.PORT = process.env.PORT || 12346; @@ -54,7 +61,9 @@ function runBenchmarks() { if (test.match(/^[\._]/)) return process.nextTick(runBenchmarks); - console.error(type + '/' + test); + if (outputFormat == 'default') + console.error(type + '/' + test); + test = path.resolve(dir, test); var a = (process.execArgv || []).concat(test); @@ -151,6 +160,10 @@ Benchmark.prototype._run = function() { return newSet; }, [[main]]); + // output csv heading + if (outputFormat == 'csv') + console.log('filename,' + Object.keys(options).join(',') + ',result'); + var node = process.execPath; var i = 0; function run() { @@ -216,15 +229,25 @@ Benchmark.prototype.end = function(operations) { Benchmark.prototype.report = function(value) { var heading = this.getHeading(); - if (!silent) + + if (outputFormat == 'default') console.log('%s: %s', heading, value.toFixed(5)); + else if (outputFormat == 'csv') + console.log('%s,%s', heading, value.toFixed(5)); process.exit(0); }; Benchmark.prototype.getHeading = function() { var conf = this.config; - return this._name + ' ' + Object.keys(conf).map(function(key) { - return key + '=' + conf[key]; - }).join(' '); + + if (outputFormat == 'default') { + return this._name + ' ' + Object.keys(conf).map(function(key) { + return key + '=' + conf[key]; + }).join(' '); + } else if (outputFormat == 'csv') { + return this._name + ',' + Object.keys(conf).map(function(key) { + return conf[key]; + }).join(','); + } };