# TODO:  Update this using microbenchmark


library(compiler)

numberOfTrials <- 5
loops <- 50^3
data  <- 1:10


BracesTest <- function(numberOfTrials=10, loops=50^4, data=1:10) {
  withBraces <- withoutBraces <- numeric(numberOfTrials)
  for (j in 1:numberOfTrials) {
    withBraces[j]    <- system.time(for(i in 1:loops) {mean(2+(1:10))})[3]
    withoutBraces[j] <- system.time(for(i in 1:loops)  mean(2+(1:10)))[3]
  }
results <- (paste0("\tWITH   :  mean: ", form(mean(withBraces)), "  !  var: ", form(var(withBraces)), "\n",
       "\tWITHOUT:  mean: ", form(mean(withoutBraces)), "  !  var: ", form(var(withoutBraces)), "\n"))
return(results)
}
BracesTestCompiled <- cmpfun(BracesTest)

# Run test uncompiled
cat("Uncompiled Test:\n")
retUncomp <- BracesTest(numberOfTrials, loops, data)
cat(retUncomp)

# Run test compiled
cat("Compiled Test:\n")
retComp <- BracesTestCompiled(numberOfTrials, loops, data)
cat(retComp)
