Stopwatch function in R

前端 未结 10 2010
后悔当初
后悔当初 2020-12-08 07:27

Is there an R timer or stopwatch function similar to MATLAB\'s tic/toc?

10条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 07:59

    No, but here is a one line solution.

    time.it<-function(f) { a<-proc.time(); out<-f(); print(proc.time()-a); out }
    

    And an example for usage:

    result<-time.it(function(){ A<-matrix(runif(5000^2),nrow=5000); b<-runif(5000); solve(A,b) } )
    user  system elapsed 
    12.788  12.268   8.623 
    

    Otherwise, microbenchmark is my favorite in terms of packages.

提交回复
热议问题