Two solutions for progress bar... not equivalent
To make a progress bar, you have two main solutions:
In library utils: txtProgressBar()
In library progress: progress_bar$new()
The second one makes a progress bar with automatic "estimated time to arrival". This is very useful. However, it does that functionality at a cost.
Let do 3 examples: without progress bar, with a txtProgressBar() and with a progress_bar$new() (see below for the codes).
The code is ran in Rstudio, R GUI and in terminal under MacOSX:
Rstudio:
> A[3]/R[3]
elapsed
8.235853
> B[3]/R[3]
elapsed
1.835827
R GUI:
> A[3]/R[3]
elapsed
7.895495
> B[3]/R[3]
elapsed
1.181143
R in terminal:
In conclusion, the progress_bar$new() is between 5 to 8 time slower than the txtProgressBar(). It is nicer but it has a cost !
R <- system.time({
Total <- 50000
for (annee in 1:Total) {
Sys.sleep(0.0001)
}
})
library("progress")
A <- system.time({
Total <- 50000
pb <- progress_bar$new(
format = " completion [:bar] :percent eta: :eta",
total = Total, clear = FALSE)
for (annee in 1:Total) {
pb$tick()
Sys.sleep(0.0001)
}
cat("\n")
})
library("utils")
B <- system.time({
Total <- 50000
pb <- txtProgressBar(min=0, max=Total, style=3)
for (annee in 1:Total) {
setTxtProgressBar(pb, annee)
Sys.sleep(0.0001)
}
cat("\n")
})
A[3]/R[3]
B[3]/R[3]
In library utils: txtProgressBar()
In library progress: progress_bar$new()
The second one makes a progress bar with automatic "estimated time to arrival". This is very useful. However, it does that functionality at a cost.
Let do 3 examples: without progress bar, with a txtProgressBar() and with a progress_bar$new() (see below for the codes).
The code is ran in Rstudio, R GUI and in terminal under MacOSX:
Rstudio:
> A[3]/R[3]
elapsed
8.235853
> B[3]/R[3]
elapsed
1.835827
R GUI:
> A[3]/R[3]
elapsed
7.895495
> B[3]/R[3]
elapsed
1.181143
R in terminal:
> A[3]/R[3]
elapsed
10.74719
> B[3]/R[3]
elapsed
2.079948
In conclusion, the progress_bar$new() is between 5 to 8 time slower than the txtProgressBar(). It is nicer but it has a cost !
R <- system.time({
Total <- 50000
for (annee in 1:Total) {
Sys.sleep(0.0001)
}
})
library("progress")
A <- system.time({
Total <- 50000
pb <- progress_bar$new(
format = " completion [:bar] :percent eta: :eta",
total = Total, clear = FALSE)
for (annee in 1:Total) {
pb$tick()
Sys.sleep(0.0001)
}
cat("\n")
})
library("utils")
B <- system.time({
Total <- 50000
pb <- txtProgressBar(min=0, max=Total, style=3)
for (annee in 1:Total) {
setTxtProgressBar(pb, annee)
Sys.sleep(0.0001)
}
cat("\n")
})
A[3]/R[3]
B[3]/R[3]
Commentaires
Enregistrer un commentaire