[Rcpp-devel] R vectorisation vs. C++ vectorisation

Darren Cook darren at dcook.org
Tue Nov 20 01:09:19 CET 2012


> * vacc3: vectorised with loop in C++

I shaved a bit off this with a simple micro-optimization. In vacc3a replace:
  p = std::max(p, 0.0);
  p = std::min(p, 1.0);

with:
  if(p<0.0)p=0.0;else if(p>1.0)p=1.0;   //Clip

I called it vacc6, and a couple of runs are shown below. It is worth
about 4-5% (on the median time).

(Maybe this dilutes your point about comparing vectorization approaches;
but I think it is important to note that loops offer you this possibility.)

Darren


                     expr       min        lq     median         uq
  max
1 vacc1(age, female, ily) 10180.614 10531.933 10888.4910 11289.1540
42388.079
2 vacc2(age, female, ily)   330.790   337.499   362.4295   404.7460
516.647
3 vacc3(age, female, ily)    44.270    46.742    51.5535    55.7330
72.879
4 vacc4(age, female, ily)    56.375    58.562    66.2860    71.2345
97.836
5 vacc5(age, female, ily)    45.483    49.820    53.0070    58.3720
81.354
6 vacc6(age, female, ily)    44.304    45.610    49.7165    56.5450
69.215



                     expr       min         lq     median         uq
   max
1 vacc1(age, female, ily) 10406.705 10594.7065 10928.0790 11216.0370
15318.001
2 vacc2(age, female, ily)   327.804   331.9610   354.8430   363.3185
462.903
3 vacc3(age, female, ily)    44.013    45.7835    49.1725    56.7800
124.539
4 vacc4(age, female, ily)    56.354    58.3935    62.1805    69.9180
106.800
5 vacc5(age, female, ily)    44.897    46.5435    49.9435    57.9220
72.421
6 vacc6(age, female, ily)    44.124    45.0205    47.0645    54.1135
80.783




More information about the Rcpp-devel mailing list