首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当R是用--启用--R-分析和--启用--内存分析--而不是同时使用--两种方法编译时,我的性能会下降多少?

当R是用--启用--R-分析和--启用--内存分析--而不是同时使用--两种方法编译时,我的性能会下降多少?
EN

Stack Overflow用户
提问于 2019-09-02 11:58:18
回答 1查看 142关注 0票数 2

在使用Rprof时,需要用--enable-R-profiling编译R,使用Rprofmem时需要用--enable-memory-profiling编译R。像profmembenchprofvis这样的工具也使用了这个编译时选项。

Rprofmem手册中,我可以读到:内存分析器甚至在不使用__时也会降低R的速度,编译时选项也是如此。它是在标准Windows版本中启用的,但是当您自己编译它时,默认情况下是禁用的。

R使用--enable-R-profiling和/或--enable-memory-profiling编译时,与使用--disable-R-profiling--disable-memory-profiling编译的版本相比,当两者都不使用时,性能会下降多少?

使用和不使用R-profilingmemory-profiling运行以下代码需要多长时间。该代码估计了一个非线性最小二乘回归,并且正在以一种不明智的方式更新数据。也许有人知道一个能更好地显示性能差异的例子。

也许这种差异取决于操作系统,正如Rprof的手册所说:在Unix-相似:分析并不是在所有的平台上可用。

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-02 12:23:45

当我运行代码时,我会得到以下时间:

代码语言:javascript
复制
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并显示结果。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57756583

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档