From dda466b753850fd0f54e690021390130482e4f82 Mon Sep 17 00:00:00 2001 From: Brendan Ashworth Date: Mon, 9 Feb 2015 19:36:52 -0800 Subject: [PATCH 1/3] 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. --- benchmark/common.js | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/benchmark/common.js b/benchmark/common.js index c4a5f7ebb6620c..559dbb182c2434 100644 --- a/benchmark/common.js +++ b/benchmark/common.js @@ -4,6 +4,7 @@ var path = require('path'); var spawn = require('child_process').spawn; var silent = +process.env.NODE_BENCH_SILENT; +var outputFormat = process.env.OUTPUT_FORMAT || 'default'; exports.PORT = process.env.PORT || 12346; @@ -44,7 +45,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 +142,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 +210,29 @@ Benchmark.prototype.end = function(operations) { Benchmark.prototype.report = function(value) { var heading = this.getHeading(); - if (!silent) - console.log('%s: %s', heading, value.toFixed(5)); + + 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(','); + } else { + throw new Error('OUTPUT_FORMAT set to invalid value'); + } }; From 21ae52cc65b7d27cdf0f43675d4282aaee70af30 Mon Sep 17 00:00:00 2001 From: Brendan Ashworth Date: Mon, 9 Feb 2015 19:36:52 -0800 Subject: [PATCH 2/3] 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. --- benchmark/common.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/benchmark/common.js b/benchmark/common.js index 559dbb182c2434..b87460b3c02ef4 100644 --- a/benchmark/common.js +++ b/benchmark/common.js @@ -3,8 +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 || 'default'; +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; @@ -211,12 +217,10 @@ 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)); - } + 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); }; @@ -232,7 +236,5 @@ Benchmark.prototype.getHeading = function() { return this._name + ',' + Object.keys(conf).map(function(key) { return conf[key]; }).join(','); - } else { - throw new Error('OUTPUT_FORMAT set to invalid value'); } }; From 6389c588308f7bae3536ecc597efadba2617cddb Mon Sep 17 00:00:00 2001 From: Brendan Ashworth Date: Mon, 9 Feb 2015 20:25:47 -0800 Subject: [PATCH 3/3] benchmark: add plot_csv R graphing script This commit adds a graphing script (in R) for graphing the CSV output of a benchmark. It can be run like this: ``` $ OUTPUT_FORMAT=csv iojs benchmark/http/client-request-body.js > data.csv $ ./benchmark/plot_csv.R data.csv graph.png bytes type ``` This will graph the output to `graph.png`, using the output's `bytes` value as X and the result value for each as Y. Output will be grouped by `type`. Running as the example yields a beautiful graph like this: http://pbrd.co/1vBhUfy. --- benchmark/plot_csv.R | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 benchmark/plot_csv.R 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'))