Measuring elapsed time
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.
当前内容版权归 cookbook-r.com 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 cookbook-r.com .