[R] R perfomance question !!!

Ben Bolker bolker at ufl.edu
Wed Jun 18 22:14:54 CEST 2008


diver495 <ansolid <at> gmail.com> writes:

> 
> 
> I ran the simple script bellow and received shoking results. It was complied
> for about 15 seconds !!! on modern Intel Core Duo computer.
> 
> i=0;
> while(i<5000000)
> {
>     i=i+1;
> }
> 
> Using Visual Basic I can complete the same script (simple loop of 5000000
> itterations) in 0.1 sec.
> Is it realy R not suitable for huge computing.

  9.25 seconds for me.
  Every language has its strong and weak points, and every
language has its idioms.  Depending on what you want to do you
may be able to figure out a way to do it quickly in R
(and the folks on this list might be able to help).
People do lots of "huge computing" in R, but
brute-force approaches may be slow.
For example sum(as.numeric(1:5e6)) takes 0.06 seconds
while the equivalent summation
i=0;s=0;system.time(while (i<5e6) { i <- i+1; s <- s+i })
takes 17 seconds.
(While we're at it, the equivalent "for loop"
to the while loop above
system.time(for (i in 1:5e6) { })
takes 1.6 seconds on my machine)
If Visual Basic does what you need, use it ...

   Ben Bolker



More information about the R-help mailing list