loop ↔ vectorized ↔ direct [Two-Stage / GS Designs]

posted by ElMaestro  – Belgium?, 2017-08-20 15:22 (1083 d 02:34 ago) – Posting: # 17721
Views: 24,529

Hi Hötzi,

» Later down you makes calls to vecQT1[df] and vecQT2[df]. That’s awfully slooow. Why not simply call qt(p=foo, df=bar) directly?

That kind of benchmarking is misleading. Here you are doing the vectorise operation of array generation numerous times which will never happens in practice; you only need to initialise the arrays once within every run of 1000000 iterations, possible even keep the arrays/vectors across runs.

I agree that whole "once" operation is faster when you use
vecQT1 <- qt(p=1-alpha1, df=1:5000)
(I had no idea you could do that, actually)
, but if you benchmark the entire you you will see the difference may be a few microsecs out of numerous seconds or minutes. Saving 0.0001% time? That's not optimization, it beautification or achieving the same with fewer lines of code which isn't what I am after.

I am not very experienced with vectorised functions at all - I understand code better if loops are visible.:-D That's just me, of course.

I could be wrong, but...

Best regards,
ElMaestro

"Pass or fail" (D. Potvin et al., 2008)

Complete thread:

Activity
 Admin contact
20,977 posts in 4,374 threads, 1,460 registered users;
online 21 (0 registered, 21 guests [including 13 identified bots]).
Forum time: Friday 17:56 CEST (Europe/Vienna)

When someone says his conclusions are objective,
he means that they are based on prejudices
which many other people share.    Celia Green

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