performance of apply

Peter Dalgaard BSA p.dalgaard@biostat.ku.dk
29 May 1998 18:04:30 +0200


Luke Tierney <luke@stat.umn.edu> writes:


> > > That is, the computation of the sums of the rows of a 10000x10 matrix
> > > with apply takes about 100sec on average, where a simple for-loop does
> > > the same job in about 2sec.
> 
> It looks like M1 and M3 are O(n^2) but M1 is O(n). I see where that
> comes from in M3, but it surprises me for M1.

Oh, dear. Looking at apply, we have right in the middle of it:

            for (i in 1:d2) ans[[i]] <- FUN(array(newX[, i], d.call, 
                    dn.call), ...)

Assignment to the tail of a very long list... 

I think I'm beginning to understand why Ross keeps talking about
generic vectors. Either that or we need to add some low-level list
primitives to the language. 

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._