我想了解 R 的 microbenchmark 和 system.time() 之间的区别?他们如何在内部测量函数执行时间?
在这两种情况下,运行时间都是使用操作系统工具计算的,因此
如何计算运行时间取决于操作系统。
如详细信息部分所述?system.time http://www.inside-r.org/r-doc/base/system.time:
system.time 调用函数 proc.time,计算 expr,然后
再次调用 proc.time,返回两者之间的差值
proc.time 调用。
proc.time http://www.inside-r.org/r-doc/base/proc.time是原始的,C 代码位于src/main/times.c http://svn.r-project.org/R/trunk/src/main/times.c。该文件状态中的注释:
proc.time() 使用 currentTime() 来获取经过的时间,然后使用 getrusage
类似 Unix 上的 CPU 时间,Windows 上的 GetProcessTimes。
从注释部分?microbenchmark http://www.inside-r.org/packages/cran/microbenchmark/docs/microbenchmark page:
根据底层操作系统的不同,有不同的方法
用于计时。在 Windows 上,QueryPerformanceCounter 接口是
用于测量经过的时间。对于 Linux,clock_gettime API 是
在 Solaris 上使用 gethrtime 函数。最后在 MacOS X 上,
未记录,mach_absolute_time 函数用于避免
对 CoreServices 框架的依赖。
我找不到微基准存储库,因此您必须下载源代码才能查看确切的详细信息,但时间是由do_microtiming
in src/nanotimer.c
,它调用依赖于操作系统的版本get_nanotime
, in src/nanotimer_nanotimer_gettime.h
/src/nanotimer_nanotimer_macosx.h
/src/nanotimer_nanotimer_rtposix.h
/src/nanotimer_nanotimer_windows.h
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)