Problem
Inside the loop :
for(n in n_cores){
. . .
time_taken <- round(end_time - start_time, digits = 2)
. . .
time_runs <- c(time_runs, time_taken)
}
Calculation of time_taken returns false results for the minute long runs probably an issue with round() function that coerces the diff_time object: end_time - start_time
Visualize the error later
plot(n_cores, time_runs)
Plot shows only couple seconds timed runs with 2,3 and 4 core usage
### Proposed fix
Replace line :
r
time_taken <- round(end_time - start_time, digits = 2)
with :
r
time_taken <- round(as.numeric(end_time - start_time, units = "secs"), 2)
Fix produces expected behavior : with 2,3 and 4 core usage runs take couple minutes to complete