Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: add csv and plotting script #777

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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(',');
}
};
38 changes: 38 additions & 0 deletions benchmark/plot_csv.R
Original file line number Diff line number Diff line change
@@ -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'))