GKi
GKi

Reputation: 39717

How much performance do I loose when R is compiled with --enable-R-profiling and --enable-memory-profiling but not using both?

When using Rprof R needs to be compiled with --enable-R-profiling, when using Rprofmem R needs to be compiled with --enable-memory-profiling. Tools like profmem, bench or profvis also make use of this compile-time options.

In the manual of Rprofmem I can read: The memory profiler slows down R even when not in use, and so is a compile-time option. It is enabled in a standard Windows build, but when you compile it by your own it is disabled by default.

How much performance do I loose when R is compiled with --enable-R-profiling and / or --enable-memory-profiling compared to a version compiled with --disable-R-profiling and --disable-memory-profiling when both are not in use?

How long does I take to run the following code with and without R-profiling and memory-profiling. The code estimates a Nonlinear Least Squares Regression and is updating data in a unclever way. Maybe someone knows an example which can show performance differences better.

Maybe this difference depends on the operating system as the manual of Rprof says: On Unix-alikes: Profiling is not available on all platforms.

set.seed(7)
n  <- 1e6
x  <- data.frame(a=rnorm(n), b=abs(rnorm(n)))
x$a  <- x$a + x$b^2

y  <- x

library(microbenchmark)
microbenchmark(local(for(i in seq_len(nrow(x) %/% 1000)) {x[1,]  <- x[1,] * runif(1)}), times=10) #Update data
microbenchmark(local(a  <- nls(a ~ c0 + c1*b^c2, data=x, start=list(c0=0, c1=1, c2=1))), times=10) #Make regression

Upvotes: 2

Views: 177

Answers (1)

GKi
GKi

Reputation: 39717

When I run the code I get the following times:

microbenchmark(for(i in seq_len(nrow(y) %/% 1000)) {y[1,]  <- y[1,] * runif(1)}, times=10, setup = y  <- x)
#     min       lq     mean   median       uq      max neval R-profiling memory-profiling       OS
# 6.708744 6.806145 6.821143 6.823692 6.847541 6.938885   10    disabled         disabled Debian10
# 6.464093 6.477556 6.493352 6.491386 6.509931 6.525003   10     enabled         disabled Debian10
# 6.411479 6.417158 6.468241 6.425521 6.484717 6.744321   10    disabled          enabled Debian10
# 6.454901 6.460453 6.534845 6.498163 6.543412 6.802233   10     enabled          enabled Debian10
# 9.432436 9.460503 9.486715 9.485126 9.509481 9.549586   10     enabled          enabled       W7

microbenchmark(a  <- nls(a ~ c0 + c1*b^c2, data=x, start=list(c0=0, c1=1, c2=1)), times=10)
#      min       lq     mean   median       uq      max neval R-profiling memory-profiling       OS
# 2.381535 2.410108 2.4401   2.42579  2.454314 2.575013    10    disabled         disabled Debian10
# 2.34416  2.371159 2.408136 2.388185 2.418468 2.564823    10     enabled         disabled Debian10
# 2.508877 2.530593 2.569831 2.562261 2.593255 2.725677    10    disabled          enabled Debian10
# 2.365148 2.381606 2.435109 2.422114 2.461816 2.573329    10     enabled          enabled Debian10
# 3.853165 3.855415 3.898948 3.878377 3.914975 4.037514    10     enabled          enabled       W7

#OS: Debian10 .. compiled using the sources of 3.6.1 on standard Debian 10 amd64
#    W7       .. using the 3.6.1 Windows binary from CRAN on Windows7

R compiled on Linux will not show notable performance differences when running the two examples. Unfortunately I'm not able to compile R also on Windows and show results.

Upvotes: 3

Related Questions