\HeaderA{system.time}{CPU Time Used}{system.time}
\aliasA{unix.time}{system.time}{unix.time}
\keyword{utilities}{system.time}
\begin{Description}\relax
Return CPU (and other) times that \code{expr} used.
\end{Description}
\begin{Usage}
\begin{verbatim}
system.time(expr, gcFirst = TRUE)
unix.time(expr, gcFirst = TRUE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{expr}] Valid \R{} expression to be timed.
\item[\code{gcFirst}] Logical - should a garbage collection be performed
immediately before the timing?  Default is \code{TRUE}.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{system.time} calls the function \code{\LinkA{proc.time}{proc.time}},
evaluates \code{expr}, and then calls \code{proc.time} once more,
returning the difference between the two \code{proc.time} calls.

\code{unix.time} is an alias of \code{system.time}, for
compatibility with S.

Timings of evaluations of the same expression can vary considerably
depending on whether the evaluation triggers a garbage collection. When
\code{gcFirst} is \code{TRUE} a garbage collection (\code{\LinkA{gc}{gc}})
will be performed immediately before the evaluation of \code{expr}.
This will usually produce more consistent timings.
\end{Details}
\begin{Value}
A object of class \code{"proc\_time"}: see
\code{\LinkA{proc.time}{proc.time}} for details.
\end{Value}
\begin{Note}\relax
It is possible to compile \R{} without support for \code{system.time},
when the function will throw an error.
\end{Note}
\begin{SeeAlso}\relax
\code{\LinkA{proc.time}{proc.time}}, \code{\LinkA{time}{time}} which is for time series.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
require(stats)
system.time(for(i in 1:100) mad(runif(1000)))
## Not run: 
exT <- function(n = 1000) {
  # Purpose: Test if system.time works ok;   n: loop size
  system.time(for(i in 1:n) x <- mean(rt(1000, df=4)))
}
#-- Try to interrupt one of the following (using Ctrl-C / Escape):
exT()                 #- about 3 secs on a 1GHz PIII
system.time(exT())    #~ +/- same
## End(Not run)\end{ExampleCode}
\end{Examples}

