system.time
CPU Time Used

Description

Calculates the CPU time that "expr" uses.

Usage

system.time(expr, gcFirst = TRUE)
unix.time(expr, gcFirst = TRUE)

Arguments

expr an expression that takes CPU time.
gcFirst a logical value. If TRUE (the default), specifies that garbage collection occurs before timing "expr".

Details

if "expr" is omitted, system.time retrieves the CPU usage time and shows the error condition. If any child processes are spawned during the current session, system.time cumulates them to user and system times.
Value
returns a numeric vector of class proc_time, identified by: giving the user, system, and elapsed times for the currently running engine process, in units of seconds.
The print and summary methods for proc_time add the child times to the corresponding self times and labels them "user", "system", and "elapsed".
See Also
proc.time
Examples
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)

Package base version 6.0.0-69
Package Index