r - system.time 的多功能测试器替代品

标签 r

我已经看到(我认为在 SO 上)使用类似于 system.time 的函数一次评估多个函数的时间并输出一个输出。我不记得它是什么,并且使用我正在使用的术语进行互联网搜索并没有产生我想要的响应。

有人知道我正在谈论的功能的名称/位置吗?

最佳答案

您想要 rbenchmark包装及其 benchmark功能。 (还有相关且更专业的 microbenchmark 包。)

这是示例部分的开头:

R> example(benchmark)

bnchmrR> # example 1
bnchmrR> # benchmark the allocation of one 10^6-element numeric vector,
bnchmrR> # replicated 100 times
bnchmrR> benchmark(1:10^6)
    test replications elapsed relative user.self sys.self user.child sys.child
1 1:10^6          100   0.286        1       0.2     0.08          0         0

bnchmrR> # Example 2
bnchmrR> # A call to benchmark with two named expressions and three replication
bnchmrR> # counts, output sorted by the replication counts and then by the 
bnchmrR> # elapsed time:
bnchmrR> means.rep = function(n, m)
bnchmr+    mean(replicate(n, rnorm(m)))

bnchmrR> means.pat = function(n, m)
bnchmr+    colMeans(array(rnorm(n*m), c(m, n)))

bnchmrR> benchmark(
bnchmr+    rep=means.rep(100, 100),
bnchmr+    pat=means.pat(100, 100),
bnchmr+    replications=10^(1:3),
bnchmr+    order=c('replications', 'elapsed'))
  test replications elapsed  relative user.self sys.self user.child sys.child
4  pat           10   0.011   1.00000      0.02        0          0         0
1  rep           10   0.015   1.36364      0.02        0          0         0
5  pat          100   0.107   9.72727      0.10        0          0         0
2  rep          100   0.155  14.09091      0.16        0          0         0
6  pat         1000   1.073  97.54545      1.07        0          0         0
3  rep         1000   1.553 141.18182      1.55        0          0         0

关于r - system.time 的多功能测试器替代品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8439957/

相关文章:

r - Solr 索引中的聚类文档(具有自定义距离)

r - 将行值与列名匹配并在 R 中提取值

xml - 在 R 中解析 iTunes RSS

r - 没有循环的数据框中的子字符串,填充和粘贴列

r - 使用knitr绘制图的位置

使用跨替换 group_by_at(NULL)

R 编程 : read. csv() 意外跳过行

r - Leaflet Shiny 标记弹出窗口中的格式问题

r - 如何在 R 中的并行方法中使用无用的记录器进行记录?

r - fread{data.table} 中的错误