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.
EDIT: 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)
}
Usage is, e.g., tic(); invisible(qr(matrix(runif(1e6), nrow=1e3))); toc()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…