monkyvirus
monkyvirus

Reputation: 33

Using system.time in R, getting very varied times

I have written two functions in R and I need to see which is faster so I used system.time. However, the answers are so varied I can't tell. As its for assessed work I don't feel I can actually post the code (in case someone corrects it). Both functions call rbinom to generate multiple values and this is the only part that isn't a simple calculation.

The function time needs to be as fast as possible but both are returning times of anywhere between 0.17 and 0.33. As the mark is 0.14/(my function time) x 10 it's important I know the exact time.

I have left gcFirst=TRUE as recommended in the R help.

My question is why are the times so inconsistent? Is it most likely to be the functions themselves, my laptop or R?

Upvotes: 3

Views: 233

Answers (1)

Dirk is no longer here
Dirk is no longer here

Reputation: 368191

You probably want to use one of the benchmarking packages

for this. And even then, variability will always enter. Benchmarking and performance testing is not the most exact science.

Also see the parts on profiling in the "Writing R Extensions" manual.

Upvotes: 4

Related Questions