Skip to content

Instantly share code, notes, and snippets.

@JasonPunyon
Last active May 4, 2018 04:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JasonPunyon/fb6e92a0973f9429a065aac7acf2a4cd to your computer and use it in GitHub Desktop.
Save JasonPunyon/fb6e92a0973f9429a065aac7acf2a4cd to your computer and use it in GitHub Desktop.
Graph the output of go bench
# These lines only need to be run once on each machine to install the libraries I use below.
install.packages("tidyverse")
install.packages("devtools")
devtools::install_github("dgrtwo/drlib")
# End
#After you run those ^^ remove them and save the file...
#Then from a terminal...
#Rscript gobench-plotter.R gobench.input output.png
#Parse the command
args = commandArgs(trailingOnly=TRUE) # this line only works when you run this script from the command line.
#Run from the command line like this...
#Rscript gobench-plotter.R gobench.out plot.png
library(tidyverse)
library(drlib)
plot = readr::read_delim(args[1], "\t", skip = 5, col_names = FALSE) %>%
set_names("Name", "Ops", "NsPerOp", "MBPerS", "AllocatedBytesPerOp", "AllocationsPerOp") %>%
#Clean up the text so we get numbers...
mutate(NsPerOp = as.numeric(str_replace(NsPerOp, " ns/op", "")),
MBPerS = as.numeric(str_replace(MBPerS, " MB/s", "")),
AllocatedBytesPerOp = as.numeric(str_replace(AllocatedBytesPerOp, " B/op", "")),
AllocationsPerOp = as.numeric(str_replace(AllocationsPerOp, " allocs/op", "")),
Ops = as.numeric(Ops)) %>%
filter(!is.na(NsPerOp)) %>%
#Split out the cores...
separate(Name, c("Name", "Cores"), "-") %>%
mutate(Cores = as.numeric(Cores)) %>%
#Split out the bytes...
separate(Name, c("Name", "Bytes"), "/") %>%
mutate(Bytes = as.numeric(Bytes)) %>%
#Plot
ggplot(aes(Name, NsPerOp)) +
geom_col() +
rotate_x_labels(vjust = .5) +
facet_wrap(~ Bytes, scales="free_y")
ggsave(args[2], plot, width = 16, height = 9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment