[R] R perfomance question !!!

Philippe Grosjean phgrosjean at sciviews.org
Thu Jun 19 09:38:39 CEST 2008


Hello,
Do you really need to read these data that often? What's the amount of 
data you read at each iteration? What's the buffer capacity of your 
system for sending these data? Couldn't you read data every 1/10 second 
(or another, better suited interval)? For instance, something like:

x <- GiveNextDataPortion()
while (!is.null(x)) {
     Sys.sleep(0.1)
     x <- GiveNextDataPortion()
}

If not, consider using C code, or the embedded Tcl (with the tcltk 
package) that has a very nice mechanism for I/O management in situations 
like this (google a little bit to find examples of use, or look at the 
svSocket or Rpad packages for examples of use in R).
Best,

Philippe Grosjean

..............................................<°}))><........
  ) ) ) ) )
( ( ( ( (    Prof. Philippe Grosjean
  ) ) ) ) )
( ( ( ( (    Numerical Ecology of Aquatic Systems
  ) ) ) ) )   Mons-Hainaut University, Belgium
( ( ( ( (
..............................................................

diver495 wrote:
> The main task is computing of consistently received data. I have a function
> named "GiveNextDataPortion()" that returns the list object. The number of
> function's calls is about 5 millions and thus, I encountered a problem of
> perfomance.
> 
> I use this script:
> 
> x<-GiveNextDataPortion()
> while(is.null(x)==FALSE)
> {
>     x<-GiveNextDataPortion()
> }
> 
> 5 millions iterations of "while" loop takes about 20 seconds on my computer,
> it is very quickly, but adding some simple extra operators increases the
> time of test a lot. 
> For example:
> 
> x<-GiveNextDataPortion()
> i=0
> j=1
> while(is.null(x)==FALSE)
> {
>    x<-GiveNextDataPortion()
>    i=i+1
>    j= j*i
> }
> 
> It will already take more than 10 minutes. 
> 
> Have you any ideas about the optimization of this test?
> 
> 
> Roland Rau-3 wrote:
>> Hi,
>>
>> diver495 wrote:
>>> 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.
>> If you are happy with Visual Basic, then there is no need for you to use
>> R.
>> In case your message was not a flamebait, it is well known that loops 
>> like these are often bottlenecks for R.
>>
>> There are many resources how to easily avoid them. See, for example, "S 
>> Programming by Venables and Ripley or John Chambers' book: Programming 
>> with data.
>> Even searching the mail archive for subject like "avoid loops" might be 
>> helpful.
>> You might also consider checking functions like apply, tapply, ...
>>
>> Best,
>> Roland
>>
>> P.S.
>> It seems there is also a good book available for scientific computing 
>> with Visual Basic:
>> http://www.ibiblio.org/Dave/Dr-Fun/df200002/df20000210.jpg
>>
>> ______________________________________________
>> R-help at 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.
>>
>>
>



More information about the R-help mailing list