从 Rprof() 获取更多信息 [英] Getting more info from Rprof()

查看:62
本文介绍了从 Rprof() 获取更多信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图深入研究我编写的一些 R 代码中的时间猪,所以我使用了 Rprof.输出还不是很有帮助:

I've been trying to dig into what the time-hogs are in some R code I've written, so I'm using Rprof. The output isn't yet very helpful though:

> summaryRprof()
$by.self
                      self.time self.pct total.time total.pct
"$<-.data.frame"           2.38     23.2       2.38      23.2
"FUN"                      2.04     19.9      10.20      99.6
"[.data.frame"             1.74     17.0       5.54      54.1
"[.factor"                 1.42     13.9       2.90      28.3
...

有什么方法可以深入挖掘并找出 $<-.data.frameFUN(可能来自 by()) 等其实是罪魁祸首?或者我是否需要重构代码并制作更小的功能块以获得更细粒度的结果?

Is there some way to dig deeper and find out which specific invocations of $<-.data.frame, and FUN (which is probably from by()), etc. are actually the culprits? Or will I need to refactor the code and make smaller functional chunks in order to get more fine-grained results?

我拒绝重构的唯一原因是我必须将数据结构传递给函数,而且所有传递都是按值传递的,所以这似乎是朝错误方向迈出的一步.

The only reason I'm resisting refactoring is that I'd have to pass data structures into the functions, and all the passing is by value, so that seems like a step in the wrong direction.

谢谢.

推荐答案

现有的 CRANprofrproftools 对此很有用.后者可以使用并非总是可以安装的 Rgraphviz.

The existing CRAN package profr and proftools are useful for this. The latter can use Rgraphviz which isn't always installable.

关于分析的 R Wiki 页面 有额外的信息和 Romain 的一个不错的脚本,它也可以可视化(但需要 graphviz).

The R Wiki page on profiling has additional info and a nice script by Romain which can also visualize (but requires graphviz).

这篇关于从 Rprof() 获取更多信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆