Running the following to test how fast runif() runs:
start_time <- Sys.time()
runif(1)
end_time <- Sys.time()
run_times= as.numeric(as.difftime(end_time - start_time, units ="secs"))
It kicks out a fraction of a second for run_times "0.3906578"
But running it in a for loop kicks out 0 each run:
nvec=c(1,100)
uni_time_vec=numeric(length(nvec))
for (i in 1:length(nvec)) {
start_time <- Sys.time()
runif(1) #hardcoded for testing
end_time <- Sys.time()
run_times= as.numeric(as.difftime(end_time - start_time, units ="secs"))
uni_time_vec[i] = run_times
}
What's happening and how can I get around it?