Speeed! [Two-Stage / GS Designs]

posted by Helmut Homepage – Vienna, Austria, 2015-02-21 02:11 (3710 d 11:20 ago) – Posting: # 14481
Views: 12,342

Hi ElMaestro,

❝ ❝ 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.


Exactly. That’s really stupid (see the R Inferno Circle 2). Detlew cured me.

❝ 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):


I have learned that one never ever should try to manipulate the counter of a for-loop. ;-)

runs <- 1e7
ptm  <- proc.time()
i    <- 1
while (i <= runs) {
  # Do.Something(i)
  i <- i+1
}
t1   <- proc.time()-ptm
ptm  <- proc.time()
i    <- 1
while (i <= runs) {
  # Do.Something(i)
  # Do.Something(i+1)
  i <- i+2
}
t2   <- proc.time()-ptm
cat("\n",
"simple :", t1[3], "seconds\n",
"partial:", t2[3], "seconds\n")

 simple : 5.07 seconds
 partial: 2.55 seconds


But: Quite often the number of iterations is not known beforehand (here it must be even) and the time-consuming part is the Do.Something().
Reminds me on my first Pascal-lessons almost 40 years ago.

Instead of    better use
y := 2*x;     y := x+x;   (addition faster than multiplication)
y := x/2;     y := 0.5*x; (multiplication faster than division)

Not kiddin’.

Dif-tor heh smusma 🖖🏼 Довге життя Україна! [image]
Helmut Schütz
[image]

The quality of responses received is directly proportional to the quality of the question asked. 🚮
Science Quotes

Complete thread:

UA Flag
Activity
 Admin contact
23,424 posts in 4,927 threads, 1,699 registered users;
25 visitors (0 registered, 25 guests [including 9 identified bots]).
Forum time: 14:32 CEST (Europe/Vienna)

Do not put your faith in what statistics say until you have carefully
considered what they do not say.    William W. Watt

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