system.time(expr, gcFirst = TRUE) unix.time(expr, gcFirst = TRUE)
| expr | an expression that takes CPU time. |
| gcFirst | a logical value. If TRUE (the default), specifies that garbage collection occurs before timing "expr". |
timeLinearAlgebra <- function(n)
{
MatA <- matrix(log2(seq_len(29*31)), nrow=29, ncol=31)
MatB <- matrix(seq_len(31*37), nrow=31, ncol=37)
# elapsed less than user+system on multicore machine
system.time(for(i in seq_len(n)) MatA %*% MatB)
}
timeLinearAlgebra(10000)
timeFileAccess <- function(n)
{
tf <- tempfile()
on.exit(unlink(tf))
# lots of system time, lots more elapsed time
system.time(for(i in seq_len(n))cat(file=tf, i, "\n", sep=""))
}
timeFileAccess(5000)