【问题标题】:What is the difference between using R microbenchmark and system.time?使用 R microbenchmark 和 system.time 有什么区别?
【发布时间】:2015-04-18 23:41:03
【问题描述】:

我想了解 R 的 microbenchmark 和 system.time() 之间的区别?他们如何在内部测量函数执行时间?

【问题讨论】:

  • ?microbenchmark 非常详细地说明了它如何测量运行时间。您具体想知道什么?
  • 这可能很有趣,来自 Radford Neal 的博客:Inaccurate results from microbenchmark
  • microbenchmark 是基于反复迭代的。 system.time 是单次运行的时间。
  • @thelatemail 您链接到的博客文章提到了微基准测试结果中缺乏均值(粗略的解释:如果您不关心垃圾收集或其他偶尔的开销时间,那么中位数更好;如果你关心,那么平均值会更好)。从那时起,该函数已更新,因此它返回两个度量,因此不再存在问题。

标签: r performance microbenchmark


【解决方案1】:

在这两种情况下,运行时间都是使用操作系统工具计算的,所以 运行时间的计算方式取决于操作系统。

?system.time 的详细信息部分所述:

system.time 调用函数 proc.time,计算 expr,然后 再次调用 proc.time,返回两者之间的差异 proc.time 调用。

proc.time 是原始的,C 代码在src/main/times.c 中。该文件状态下的评论:

proc.time() 使用 currentTime() 来表示经过的时间,然后使用 getrusage 类 Unix 上的 CPU 时间,Windows 上的 GetProcessTimes。


来自?microbenchmark 页面的备注部分:

根据底层操作系统,不同的方法是 用于计时。在 Windows 上,QueryPerformanceCounter 接口是 用来衡量经过的时间。对于 Linux,clock_gettime API 是 在 Solaris 上使用 gethrtime 函数。最后在 MacOS X 上, 未记录,mach_absolute_time 函数用于避免 对 CoreServices 框架的依赖。

我找不到 microbenchmark 存储库,因此您必须下载源代码才能看到确切的详细信息,但时间是由 do_microtiming in src/nanotimer.c 完成的,它调用了依赖于操作系统的 @ 版本987654331@,在src/nanotimer_nanotimer_gettime.h/src/nanotimer_nanotimer_macosx.h/src/nanotimer_nanotimer_rtposix.h/src/nanotimer_nanotimer_windows.h

【讨论】:

    猜你喜欢
    • 2010-11-19
    • 1970-01-01
    • 2011-04-18
    • 1970-01-01
    • 1970-01-01
    • 2019-10-26
    • 2016-01-10
    • 1970-01-01
    • 2013-04-08
    相关资源
    最近更新 更多