Speeed! [Two-Stage / GS Designs]

posted by ElMaestro  – Denmark, 2015-02-21 00:48 (4137 d 12:14 ago) – Posting: # 14480
Views: 14,680

Hi Hötzi,

❝ for(j in seq_along(run)) v1 <- c(v1, rnorm(1, mean=0, sd=1))


This is a funny way to do it. There will be constant memory re-allocation of the vector this way. I guess that's what takes the time.

Try and check if a technique called loop unrolling also helps speed things up in R. Sometimes it works miracles but is very implementation-specific. It has a little effect in my C implementations, but nothing really substantial so far.

The idea is (and pardon me for going from a for loop to a while loop; this is just because I don't know of a way to make a for loop increase by more than one per iteration, but I am sure you can do that):

In stead of

i=0
while (i<10)
{
  Do.Something(i)
  i=i+1
}


we can try

i=0
while (i<10)
{
   Do.Something(i)
   Do.Something(i+1)
   i=i+2
}


Here in stead of looping 10 times, we just need to loop 5 times. You can of course unroll a lot more than just x2 as the above example. One obvious drawback is that code can appear visually bloated but this of course doesn't affect functionality.

Pass or fail!
ElMaestro

Complete thread:

UA Flag
Activity
 Admin contact
23,655 posts in 4,993 threads, 1,570 registered users;
219 visitors (0 registered, 219 guests [including 84 identified bots]).
Forum time: 14:03 CEST (Europe/Vienna)

I have finally come to the konklusion
that a good reliable set ov bowels
iz worth more to a man
than enny quantity of brains.    Josh Billings

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5