Use system.time to time how fast R processes an expression. This function is especially useful for comparing the speed of two coding options.
- expr – An R expression to evaluate.
Example. Below we take 9 million random uniform draws between 0 and 3 using a couple of different approaches.
> system.time(runif(3000^3)*3) user system elapsed 0.339 0.071 0.407 > system.time(runif(3000^3, max=3)) user system elapsed 0.256 0.000 0.255
The output lists durations in seconds. As one might hope, proper use the arguments of the runif function makes code run faster in all types of time listed.
Tip. Most users will just care about the user listing, which indicates how long it seemed R took from the user’s perspective.