doc: improvements to console.markdown copy
[platform/upstream/nodejs.git] / benchmark / plot_csv.R
1 #!/usr/bin/env Rscript
2
3 # To use this to graph some benchmarks, install R (http://www.r-project.org/)
4 # and ggplot (http://ggplot2.org/).
5 #
6 # Once installed, you can generate some CSV output with a command like this:
7 #
8 #     $ OUTPUT_FORMAT=csv node benchmark/http/client-request-body.js > data.csv
9 #     $ ./benchmark/plot_csv.R data.csv data.png bytes type
10 #
11 # Where the 3rd argument to this script is the graph's X coordinate, the 4th is
12 # how the output is grouped, and the Y coordinate defaults to result.
13
14 library(methods)
15 library(ggplot2)
16
17 # get info from arguments
18 args <- commandArgs(TRUE)
19
20 csvFilename <- args[1]
21 graphFilename <- args[2]
22
23 xCoordinate <- args[3]
24 groupBy <- args[4]
25
26 # read data
27 data <- read.csv(file = csvFilename, head = TRUE)
28
29 # plot and save
30 plot <- ggplot(data = data, aes_string(x = xCoordinate, y = 'result', col = groupBy)) +
31         geom_point(size = 5) +
32         ggtitle(data$filename)
33
34 png(filename = graphFilename, width = 560, height = 480, units = 'px')
35 print(plot)
36 graphics.off()
37
38 cat(paste('Saved to', graphFilename, '\n'))