News

Progress bar overhead comparisons

(This article was first published on
Peter Solymos - R related posts, and kindly contributed to R-bloggers)

As a testament to my obsession with progress bars in R, here is a quick investigation about the overhead cost of drawing a progress bar during computations in R. I compared several approaches including my pbapply and Hadley Wickham’s plyr.

Let’s compare the good old lapply function from base R, a custom-made variant called lapply_pb that was proposed here, l_ply from the plyr package, and finally pblapply from the pbapply package:

Use the function f to run all four variants. The expected run time is n * s (number of iterations x sleep duration), therefore we can calculate the overhead from the return objects as elapsed minus expected. Let’s get some numbers for a variety of n values and replicated B times to smooth out the variation:

The plot tells us that the overhead increases linearly with the number of iterations when using lapply without progress bar. All other three approaches show similar patterns to each other and the overhead is constant: lines are parallel above 100 iterations after an initial increase. The per iteration overhead is decreasing, approaching the lapply line. Note that all the differences are tiny and there is no practical consequence for choosing one approach over the other in terms of processing times. This is good news and another argument for using progress bar because its usefulness far outweighs the minimal (<2 seconds here for 1000 iterations) overhead cost.

As always, suggestions and feature requests are welcome. Leave a comment or visit the GitHub repo.