Issue with "Elapsed time" in system.time function of R

r

#1

Hi All,
In order to check the amount of time my code chuck took to finish execution , i use system.time function available in R.

The output of system.time for my code chuck is

user system elapsed
0.55 2.75 72.85

As per R documentation ,

“The values presented (user, system, and elapsed) will be defined by your operating system, but generally, the user time relates to the execution of the code, the system time relates to your CPU, and the elapsed time is the difference in times since you started the stopwatch (and will be equal to the sum of user and system times if the chunk of code was run altogether).”

But, i am unable to understand , why my code is taking 72 sec as Elapsed time.
Please help.
Thanks


#2

@Rishabh0709
elapsed time works fine in my PC , can you share your sample code where you are getting this error?


#3

@HUNAIDKHAN2000 , below code took :
user system elapsed
1.75 0.41 282.02

gini <- vector(length = length(all_comb))
ks <- vector(length = length(all_comb))
dev_std_estimate <- vector("list" ,length = length(all_comb))
vif <- vector("list" ,length = length(all_comb))
coef <- vector("list" ,length = length(all_comb))

res <- paste(bad_flag,"~",sep=" ")
bad_flag_ds <- dev_data[,names(dev_data) %in% bad_flag]
frm <- sapply(all_comb,FUN = function(x) { paste0(res, x)})

system.time({
    c1 <- makeCluster(4)
  registerDoParallel(c1)
foreach(i = 1:2000 , .packages = packages) %dopar% 
 {
                         models <- glm(as.formula(frm[i]), dev_data, family = "binomial")
                         dev_pred <- predict(models , dev_data , type = "response")
                         pred <- prediction(dev_pred , bad_flag_ds)
                         perf <- performance(pred , "tpr" , "fpr")
                         auc <- performance(pred , "auc")					
                         auc_values <- auc@y.values[[1]] 		
                         gini[i] <- 2*auc_values -1 
                         ks[i] <- max(attr(perf,'y.values')[[1]]-attr(perf,'x.values')[[1]])
                         vif[[i]]<- vif(models)
                         dev_std_estimate[[i]] <- lm.beta(models)                                            
                         coef[[i]] <- summary(models)$coefficients
                        
                       }
stopCluster(c1)
})

I even tried running same code after closing all other applications on my system , but still it took same time.
Please suggest why the elapsed time is too much.
Thanks for your help.