Problem

You want to measure how much time it takes to run a particular block of code.

Solution

The system.time() function will measure how long it takes to run something in R.

system.time({
    # Do something that takes time
    x <- 1:100000
    for (i in seq_along(x))  x[i] <- x[i]+1
})
#>    user  system elapsed 
#>   0.144   0.002   0.153

The output means it took 0.153 seconds to run the block of code.