Speeed! [Two-Stage / GS Designs]

posted by ElMaestro  – Denmark, 2015-02-21 00:48 (3351 d 02:03 ago) – Posting: # 14480
Views: 11,468

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
22,993 posts in 4,828 threads, 1,656 registered users;
111 visitors (1 registered, 110 guests [including 2 identified bots]).
Forum time: 03:52 CEST (Europe/Vienna)

Never never never never use Excel.
Not even for calculation of arithmetic means.    Martin Wolfsegger

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