diff --git a/benchmark/common.js b/benchmark/common.js index c4a5f7ebb6620c..b87460b3c02ef4 100644 --- a/benchmark/common.js +++ b/benchmark/common.js @@ -3,7 +3,14 @@ var fs = require('fs'); var path = require('path'); var spawn = require('child_process').spawn; -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; @@ -44,7 +51,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); @@ -139,6 +148,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() { @@ -203,15 +216,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(','); + } }; diff --git a/benchmark/plot_csv.R b/benchmark/plot_csv.R new file mode 100755 index 00000000000000..20ab033ef9be5a --- /dev/null +++ b/benchmark/plot_csv.R @@ -0,0 +1,38 @@ +#!/usr/bin/env Rscript + +# To use this to graph some benchmarks, install R (http://www.r-project.org/) +# and ggplot (http://ggplot2.org/). +# +# Once installed, you can generate some CSV output with a command like this: +# +# $ OUTPUT_FORMAT=csv iojs benchmark/http/client-request-body.js > data.csv +# $ ./benchmark/plot_csv.R data.csv data.png bytes type +# +# Where the 3rd argument to this script is the graph's X coordinate, the 4th is +# how the output is grouped, and the Y coordinate defaults to result. + +library(methods) +library(ggplot2) + +# get info from arguments +args <- commandArgs(TRUE) + +csvFilename <- args[1] +graphFilename <- args[2] + +xCoordinate <- args[3] +groupBy <- args[4] + +# read data +data <- read.csv(file = csvFilename, head = TRUE) + +# plot and save +plot <- ggplot(data = data, aes_string(x = xCoordinate, y = 'result', col = groupBy)) + + geom_point(size = 5) + + ggtitle(data$filename) + +png(filename = graphFilename, width = 560, height = 480, units = 'px') +print(plot) +graphics.off() + +cat(paste('Saved to', graphFilename, '\n'))