Skip to content

Commit

Permalink
benchmark: add output format option [csv]
Browse files Browse the repository at this point in the history
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: #777
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
brendanashworth committed Mar 17, 2015
1 parent 97d8d49 commit c638dad
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions benchmark/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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(',');
}
};

0 comments on commit c638dad

Please sign in to comment.