[R] efficiency with "%*%"
Philippe Grosjean
phgrosjean at sciviews.org
Thu Jan 26 15:40:38 CET 2006
Excellent, but...
> x <- rnorm(1000000)
> y <- rnorm(1000000)
> system.time(x%*%y)
[1] 0.03 0.00 0.03 NA NA
> system.time(sum(x*y))
[1] 0.05 0.00 0.04 NA NA
> system.time(crossprod(x, y))
[1] 0 0 0 NA NA
So, to paraphrase a well-known contributor on this mailing list:
"Excellent! So, what did you decided to do during the next 30
milliseconds you will save by using crossprod() instead of x%*%y?
(joke)
Best,
Philippe Grosjean
P.S.: Uwe, perhaps you should consider buying a faster computer, isn't
it? :-()
Uwe Ligges wrote:
> dimitrijoe at ipea.gov.br wrote:
>
>
>>Hi,
>>
>>x and y are (numeric) vectors. I wonder if one of the following is more
>>efficient than the other:
>>
>>x%*%y
>>
>>or
>>
>>sum(x*y)
>>?
>
>
> I'd try
>
> x <- rnorm(1000000)
> y <- rnorm(1000000)
> system.time(x%*%y)
> system.time(sum(x*y))
>
> and finally (hint, hint!):
>
> system.time(crossprod(x, y))
>
> Uwe Ligges
>
>
>
>>Thanks,
>>Dimitri Szerman
>>
>>______________________________________________
>>R-help at 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
>
>
> ______________________________________________
> R-help at 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
>
>
More information about the R-help
mailing list