Re: [R] Explaining timings (was Computing sums of the columns of an array)

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Sat 06 Aug 2005 - 03:46:54 EST

On Fri, 5 Aug 2005, Liaw, Andy wrote:

>> A <- matrix(runif(5 * 731), 5)
>> system.time(replicate(1e4, rep(1, nrow(A)) %*% A), gcFirst=TRUE)
> [1] 5.28 0.13 5.46 NA NA
>> system.time(replicate(1e4, rep(1, nrow(A)) %*% A), gcFirst=TRUE)
> [1] 1.99 0.20 2.22 NA NA
>> system.time(replicate(1e4, rep(1, nrow(A)) %*% A), gcFirst=TRUE)
> [1] 1.97 0.25 2.28 NA NA
>> system.time(replicate(1e4, rep(1, nrow(A)) %*% A), gcFirst=TRUE)
> [1] 1.90 0.20 2.16 NA NA
>> system.time(replicate(1e4, colSums(A)), gcFirst=TRUE)
> [1] 1.53 0.22 1.75 NA NA
>> system.time(replicate(1e4, colSums(A)), gcFirst=TRUE)
> [1] 1.53 0.19 1.72 NA NA
>> system.time(replicate(1e4, colSums(A)), gcFirst=TRUE)
> [1] 1.51 0.19 1.70 NA NA
>> system.time(replicate(1e4, colSums(A)), gcFirst=TRUE)
> [1] 1.49 0.25 1.79 NA NA
>
> However, I don't understand why the first try took so much longer.

I've explained that to someone else earlier in the week. You need to get R's internal gc limits tuned up to match the task in hand, and on the first run it will often gc frequently. I got 90 GCs the first time, 9 the second and eventually about 7.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sat Aug 06 03:51:08 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:06:41 EST