Smith Black
Smith Black

Reputation: 535

How to check the time of a function repeated several times

Suppose i have

myFun = function(){

}

I know that

system.time(myFun) 

will tell me the time used to run the function. The question is I want to know how much would it take to repeat the calling the function 1000 times, what should I do?

Upvotes: 0

Views: 74

Answers (1)

RJ-
RJ-

Reputation: 3037

To repeat myFun 1000 times:

library(microbenchmark)
myFun <- function() {Sys.time()}
microbenchmark(myFun(), times = 1000)

Unit: microseconds
       expr   min     lq median     uq    max neval
    myFun() 9.893 11.035 11.416 12.176 60.119  1000

Upvotes: 3

Related Questions