R中的秒表功能 [英] Stopwatch function in R
本文介绍了R中的秒表功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否存在类似于MATLAB的 tic的R计时器或秒表功能/toc ?
Is there an R timer or stopwatch function similar to MATLAB's tic/toc?
推荐答案
正如Dirk所提到的,R中有很多分析工具.如果您想要tic/toc的简单性,那么也可以在R中做到这一点.
There are plenty of profiling tools in R, as Dirk mentioned. If you want the simplicity of tic/toc, then you can do it in R too.
我已经取消了MATLAB程序包中的垃圾收集功能,并且tic
现在使您可以选择对总经过时间还是仅对用户时间感兴趣.
I've cannibalised the garbage collection functionality from the MATLAB package, and tic
now lets you choose whether you are interested in total elapsed time or just the user time.
tic <- function(gcFirst = TRUE, type=c("elapsed", "user.self", "sys.self"))
{
type <- match.arg(type)
assign(".type", type, envir=baseenv())
if(gcFirst) gc(FALSE)
tic <- proc.time()[type]
assign(".tic", tic, envir=baseenv())
invisible(tic)
}
toc <- function()
{
type <- get(".type", envir=baseenv())
toc <- proc.time()[type]
tic <- get(".tic", envir=baseenv())
print(toc - tic)
invisible(toc)
}
用法是例如tic(); invisible(qr(matrix(runif(1e6), nrow=1e3))); toc()
这篇关于R中的秒表功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文