[R] microbenchmark

Hadley Wickham h.wickham at gmail.com
Tue Sep 17 23:47:25 CEST 2013


I'm not sure why either, but here's a simpler (and much faster)
illustration of the problem:

library(microbenchmark)

A <- matrix(1:9,3)

replicate(10, microbenchmark(colMeans(A), times = 4)$time)
replicate(10, microbenchmark(A, times = 4)$time)

Hadley

On Mon, Sep 16, 2013 at 8:11 AM, Christophe Genolini
<cgenolin at u-paris10.fr> wrote:
> Hi the list,
>
> I am using the function microbenchmark to measure the performance of some
> code. But I notice that the first execution of the code takes much longueur
> than the next executions.
> I compare it to several executions of the code :
>
> --- 8< ----------
> A <- matrix(1:9,3)
> nbReroll <- 1000
> temps <- matrix(NA,1000,2)
> temps[,1] <- microbenchmark(colMeans(A),times=nbReroll)$time
>
> for(j in 1:nbReroll){
>     temps[j,2] <- microbenchmark(colMeans(A),times=1)$time
> }
>
> --- 8< -----------
> Here is a plot of the result I get.
>  - In red, temps[,1], that is microbenchmarck(...,times=1000)
>  - In blue temps[,2], that is for(i in 1:1000)microbenchmark(...times=1)
>
>
> So why is there such a bid difference? What is the correct execution time
> for my instruction?
>
> Christophe
>
> --
> Christophe Genolini
> Maître de conférences en bio-statistique
> Vice président Communication interne et animation du campus
> Université Paris Ouest Nanterre La Défense
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Chief Scientist, RStudio
http://had.co.nz/



More information about the R-help mailing list