[R] More simple implementation is slow.
wl2776
wl2776 at gmail.com
Sat Jun 9 11:08:22 CEST 2012
Hi all.
I'm developing a function, which must return a square matrix.
Here is the code:
http://pastebin.com/THzEW9N7
These functions implement an analog of two embedded for cycles.
The first variant creates the resulting matrix by columns, cbind()-ing them
one by one.
The second variant creates the matrix with two columns, which rows contain
all possible
variants of i and j and calls apply on them.
The test input (data frame cp.table) can be produced with the following
commands:
> n<-132
> cpt<-data.frame(x=runif(n, min=0, max=100), y=runif(n, min=0, max=100),
> la=runif(n, min=0, max=360), phi=runif(n, min=-90, max=90))
Any random data will do.
The second variant seems to me much more readable and beauteful.
However, the first ugly variant runs much faster.
Why??
Here are the profiles:
--
View this message in context: http://r.789695.n4.nabble.com/More-simple-implementation-is-slow-tp4632872.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list