【问题标题】:R - Calculate computational cost of scripts [duplicate]R - 计算脚本的计算成本[重复]
【发布时间】:2015-06-29 20:11:17
【问题描述】:

我在 R 中有两个具有相似算法的脚本。我想通过计算成本来比较它们。我该如何计算?

谢谢。

劳尔

【问题讨论】:

  • Wall time、CPU、整体内存都是我的猜测。措施;不要计算。

标签: r algorithm code-complexity


【解决方案1】:

这是duplicate question

第一种方式:

ptm <- proc.time()
#your function here
proc.time() - ptm

或者其他方式:

system.time({ #your function here })

【讨论】:

  • 你是说system.time 不计算传递给它的表达式吗?因为那完全是错误的。或者您只是不知道您可以在其中打印,例如system.time(print(1:5)),或分配,例如system.time(x &lt;- 1:5); x
  • @Roland,你是对的,刚刚检查过。
  • 我的意思是按照 big-o 符号自动测量计算成本
  • @user3886573 我认为这个实验性问题,您可以通过测量不同时间的差异来尝试获得。初始参数。看这里en.wikipedia.org/wiki/Time_complexity
猜你喜欢
  • 2012-10-21
  • 1970-01-01
  • 1970-01-01
  • 2020-07-16
  • 1970-01-01
  • 2021-11-06
  • 2017-01-06
  • 2012-07-19
  • 1970-01-01
相关资源
最近更新 更多