1 # R script that produces histograms from benchmarked values
3 # Can be called from the bash script with the following code:
4 # export R_INPUT=$inputfile
5 # export R_OUTPUT=$outputfile
6 # export R_TYPE=$hist_type
8 # R CMD BATCH $this_script.R
10 # Rscript $this_script.R
12 # Use functions from bench.h to benchmark execution time of the desired block,
13 # then Rhist.R script to read all timings and produce histograms
14 # and finally inject.h to inject values instead of executing block
16 # This is a small function to help merging empty nbins for dhist histograms
17 merge_empty_bins <- function (h)
24 if (length(h$counts)>1)
25 for(i in 1:(length(h$counts)-1))
27 if(h$counts[i]!=0 || h$counts[i+1]!=0)
29 counts2[j]<-h$counts[i]
30 breaks2[j+1]<-h$breaks[i+1];
35 counts2[j]<-h$counts[length(h$counts)]
36 breaks2[j+1]<-h$breaks[length(h$breaks)]
45 source("analysis/hist_script/Rdhist.R")
47 inputfile<-Sys.getenv("R_INPUT")
48 outputfile<-Sys.getenv("R_OUTPUT")
49 type<-Sys.getenv("R_TYPE")
51 if (!(type %in% c("mean","default","sturges","scott")))
53 stop("Wrong histogram type")
56 df<-read.table(inputfile,header=F)
58 names(df)<-c("NAME","TIME")
61 for(i in unique(NAME))
63 vector1<-df[NAME==i,2]
65 if (length(vector1)==1)
67 #If there is only one element
68 h<-hist(vector1) # Just for R compatibility reasons
69 h$breaks<-c(vector1,vector1)
77 h<-hist(vector1) # Just for R compatibility reasons
78 h$breaks<-c(mean(vector1),mean(vector1))
79 h$counts<-length(vector1)
88 h<-dhist(vector1,nbins=type, plot = FALSE, lab.spikes = FALSE, a=5*iqr(vector1), eps=0.15)
90 h$count<-as.vector(h$counts)
92 h<-merge_empty_bins(h)
96 cat(i, file = outputfile, sep = "\t", append = TRUE)
97 cat("\t", file = outputfile, append = TRUE)
98 cat(sum(h$counts), file =outputfile, sep = "\t", append = TRUE)
99 cat("\t", file = outputfile, append = TRUE)
100 cat(sprintf("%.8f", mean(vector1)), file =outputfile, sep = "\t", append = TRUE)
101 cat("\t", file = outputfile, append = TRUE)
102 cat(length(h$breaks), file = outputfile, append = TRUE)
103 cat("\t", file = outputfile, append = TRUE)
104 cat(sprintf("%.8f", h$breaks), file = outputfile, sep = "\t", append = TRUE)
105 cat("\t", file = outputfile, append = TRUE)
106 h$density = h$counts/sum(h$counts)
107 cat(sprintf("%.8f", h$density), file = outputfile, sep = "\t", append = TRUE)
108 cat("\n", file = outputfile, append = TRUE)