Skip to content

Commit c638dad

Browse files
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: #777 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 97d8d49 commit c638dad

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

benchmark/common.js

+29-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ var fs = require('fs');
33
var path = require('path');
44
var child_process = require('child_process');
55

6-
var silent = +process.env.NODE_BENCH_SILENT;
6+
var outputFormat = process.env.OUTPUT_FORMAT ||
7+
(+process.env.NODE_BENCH_SILENT ? 'silent' : false) ||
8+
'default';
9+
10+
// verify outputFormat
11+
if (['default', 'csv', 'silent'].indexOf(outputFormat) == -1) {
12+
throw new Error('OUTPUT_FORMAT set to invalid value');
13+
}
714

815
exports.PORT = process.env.PORT || 12346;
916

@@ -54,7 +61,9 @@ function runBenchmarks() {
5461
if (test.match(/^[\._]/))
5562
return process.nextTick(runBenchmarks);
5663

57-
console.error(type + '/' + test);
64+
if (outputFormat == 'default')
65+
console.error(type + '/' + test);
66+
5867
test = path.resolve(dir, test);
5968

6069
var a = (process.execArgv || []).concat(test);
@@ -151,6 +160,10 @@ Benchmark.prototype._run = function() {
151160
return newSet;
152161
}, [[main]]);
153162

163+
// output csv heading
164+
if (outputFormat == 'csv')
165+
console.log('filename,' + Object.keys(options).join(',') + ',result');
166+
154167
var node = process.execPath;
155168
var i = 0;
156169
function run() {
@@ -216,15 +229,25 @@ Benchmark.prototype.end = function(operations) {
216229

217230
Benchmark.prototype.report = function(value) {
218231
var heading = this.getHeading();
219-
if (!silent)
232+
233+
if (outputFormat == 'default')
220234
console.log('%s: %s', heading, value.toFixed(5));
235+
else if (outputFormat == 'csv')
236+
console.log('%s,%s', heading, value.toFixed(5));
221237

222238
process.exit(0);
223239
};
224240

225241
Benchmark.prototype.getHeading = function() {
226242
var conf = this.config;
227-
return this._name + ' ' + Object.keys(conf).map(function(key) {
228-
return key + '=' + conf[key];
229-
}).join(' ');
243+
244+
if (outputFormat == 'default') {
245+
return this._name + ' ' + Object.keys(conf).map(function(key) {
246+
return key + '=' + conf[key];
247+
}).join(' ');
248+
} else if (outputFormat == 'csv') {
249+
return this._name + ',' + Object.keys(conf).map(function(key) {
250+
return conf[key];
251+
}).join(',');
252+
}
230253
};

0 commit comments

Comments
 (0)