Dear Rdevelopers
The background for this email is that I was helping a PhD student to
improve the speed of her R code. I suggested to replace calls like
t(AA)%*% BB by crossprod(AA,BB) since I expected this to be faster. The
surprising result to me was that this change actually made her code
slower.
> ## Examples :
>
> AA <- matrix(rnorm(3000*1000),3000,1000)
> BB <- matrix(rnorm(3000^2),3000,3000)
> system.time(crossprod(AA,BB),gcFirst=TRUE)
user system elapsed
24.58 0.06 24.69
> system.time(t(AA)%*%BB,gcFirst=TRUE)
user system elapsed
23.25 0.04 23.32
>
>
> AA <- matrix(rnorm(2000^2),2000,2000)
> BB <- matrix(rnorm(2000^2),2000,2000)
> system.time(crossprod(AA,BB),gcFirst=TRUE)
user system elapsed
21.94 0.03 21.98
> system.time(t(AA)%*%BB,gcFirst=TRUE)
user system elapsed
21.16 0.02 21.19
>
>
> version
_
platform i386-pc-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 2
minor 6.2
year 2008
month 02
day 08
svn rev 44383
language R
version.string R version 2.6.2 (2008-02-08)
Clearly there are many examples where crossprod is indeed faster than
t(x)%*%y,
but I suggest to change the wording in the help file for crossprod such
that it says
".... formally equivalent (but often faster than) the call t(x)%*%y ...
".
Yours
Ole Christensen
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel