簡體   English   中英

當使用 --enable-R-profiling 和 --enable-memory-profiling 編譯 R 但不同時使用兩者時,我會失去多少性能?

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

使用Rprof R需要編譯--enable-R-profiling ,使用Rprofmem R需要編譯--enable-memory-profiling profmembenchprofvis等工具也使用此編譯時選項。

Rprofmem的手冊中,我可以讀到:即使在不使用時,內存分析器也會降低 R 的速度,編譯時選項也是如此。 它在標准的 Windows 版本中啟用,但是當您自己編譯它時,默認情況下它是禁用的。

與使用--disable-R-profiling--disable-memory-profiling編譯的版本相比,使用--enable-R-profiling和/或--enable-memory-profiling編譯R時我會損失多少性能兩者都沒有使用?

使用和不使用R-profilingmemory-profiling運行以下代碼需要多長時間。 該代碼估計非線性最小二乘回歸,以不聰明的方式更新數據 也許有人知道一個可以更好地顯示性能差異的示例。

也許這種差異取決於操作系統,正如Rprof的手冊所說:在類 Unix 上:並非在所有平台上都可以進行分析。

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

當我運行代碼時,我得到以下時間:

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

在 Linux 上編譯的R在運行這兩個示例時不會表現出明顯的性能差異。 不幸的是,我也無法在 Windows 上編譯 R 並顯示結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM