Speeed! [Two-Stage / GS Designs]

posted by Helmut Homepage – Vienna, Austria, 2015-02-21 02:11 (3345 d 10:30 ago) – Posting: # 14481
Views: 11,401

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
22,987 posts in 4,824 threads, 1,664 registered users;
105 visitors (0 registered, 105 guests [including 5 identified bots]).
Forum time: 13:42 CEST (Europe/Vienna)

The only way to comprehend what mathematicians mean by Infinity
is to contemplate the extent of human stupidity.    Voltaire

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