Skip to content

Instantly share code, notes, and snippets.

@aaronberdanier
Created April 4, 2012 13:09
Show Gist options
  • Save aaronberdanier/2300959 to your computer and use it in GitHub Desktop.
Save aaronberdanier/2300959 to your computer and use it in GitHub Desktop.
R progress bar
td <- numeric(0)
ng <- 1000
### WITH A PROGRESS BAR
# create the progress bar
prog <- txtProgressBar(min=0, max=ng, char="*", style=3)
time1 <- Sys.time() # check system time
for(g in 1:ng){
# do stuff
z <- numeric(10000)
z <- rgamma(10000, 1, 1)
setTxtProgressBar(prog, g) # update the progress bar
}
close(prog) # close the progress bar
time2 <- Sys.time() # check system time
td <- rbind(td, (time2 - time1))
### WITHOUT A PROGRESS BAR
time1 <- Sys.time()
for(g in 1:ng){
z <- numeric(10000)
# do stuff
z <- rgamma(10000, 1, 1)
}
time2 <- Sys.time()
close(pb)
td <- rbind(td, (time2 - time1))
rownames(td) <- c("withTimer","withoutTimer")
colnames(td) <- "time"
td
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment