(Ted Harding) wrote: > On 03-Jan-09 18:28:03, Ben Bolker wrote: > >> Ajay Shah <ajayshah <at> mayin.org> writes: >> >>> On Sat, Jan 03, 2009 at 06:59:29PM +0100, Stefan Grosse wrote: >>> >>>> On Sat, 3 Jan 2009 22:25:38 +0530 Ajay Shah <ajayshah <at> >>>> mayin.org> wrote: >>>> >>>> AS> system.time(for (i in 1:10000000) {a[i] <- a[i] + 1}) >>>> >>>> AS> I wonder what we're doing wrong! >>>> >>>> it is no secret that R does badly with loops. Thats why it is >>>> recommended to use vectorized operations. >>>> >>> But there's a big difference even on the vectorised version: a <- a + >>> 1. Why should that be? Both systems should merely be handing down to >>> the BLAS. The (stock) R install has a less carefully setup BLAS as >>> compared with the (stock) matlab install? >>> >> See my other message. I'm suspicious of the real size of >> the difference, I think the difference could well be >> noise. Also, this particular bit of arithmetic doesn't >> involve BLAS -- see arithmetic.c (dig down until you get to >> integer_binary) ... >> Ben Bolker >> > > I just ran Ajay's examples 3 times over: > R 2.8.1 on Debian Etch using 1MB of RAM in a VirtualBox VM > running on a 1.73GHz CPU. Results: > > user system elapsed > Vector: 0.112 0.288 0.393 > Loop: 65.276 0.300 65.572 > > Vector: 0.076 0.312 0.389 > Loop: 65.744 0.332 66.076 > > Vector: 0.068 0.328 0.394 > Loop: 65.292 0.308 65.597 > > Not dissimilar to Ajay's R times (though my loop was about 50% longer). > > However, all three runs were very similar -- a little noise, > but not much! > > I don't have octave (on the same machine) to compare these with. > And I don't have MatLab at all. So I can't provide a comparison > on that front, I'm afraid. > Ted. > >
on my machine, matlab and r perform as in to ajay's results, but octave runs the for loop matlab code painfully slowly, worse than r. vQ ______________________________________________ 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.