On Wed, Jul 20, 2011 at 10:43 PM, David Winsemius <dwinsem...@comcast.net> wrote: > > On Jul 21, 2011, at 1:04 AM, Daniel Malter wrote: > >> http://mlg.eng.cam.ac.uk/dave/rmbenchmark.php >> >> I haven't ever tried it myself, but online sources suggest that Matlab >> possibly gains speed by internally avoiding loops rather than looping >> faster. What would stand at the end if this were true, however, is improved >> end user speed. > > When I ran the Toeplitz matrix creation test on a 3 year-old Mac, not the > fastest available at the time, inside their 20 run test with the outer() > function I get: > --------- > b <- outer(j, k, function(j,k) abs(j - k) + 1) > > Creation of a 220x220 Toeplitz matrix (loops)_______ (sec): 0.0034 > ------------- > When I run their code I get a number very similar to theirs: > > ------- > for (j in 1:220) { > for (k in 1:220) { > b[k,j] <- abs(j - k) + 1 > } > } > > Creation of a 220x220 Toeplitz matrix (loops)_______ (sec): 0.2338 > ----------- > > So I guess that suggests that either the loop construct or the 220 x 220 > assignments are the holdup since the calculation and single assignment > don't take much time.
Probably the assignment. See the archives. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.