[R] efficiency with "%*%"
Marc Schwartz (via MN)
mschwartz at mn.rr.com
Thu Jan 26 16:57:21 CET 2006
Perhaps you guys should try to benchmark that test on an nVidia GPU?
;-)
Best regards,
Marc
On Thu, 2006-01-26 at 15:55 +0100, Uwe Ligges wrote:
> Philippe Grosjean wrote:
>
> > 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? :-()
>
> Well, I use R, you know. It is even fast enough for my 5 year old
> laptop. For your super computer, please replace 1e6 by 1e8 in the
> example above. ;-)
>
> Uwe
>
>
> > 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
> >>>
More information about the R-help
mailing list