Dirk Eddelbuettel — written Dec 26, 2012 — source
Simulation studies can run for a long time, and frequently lead to benchmarking and timing studies comparing implementations and algorithms.
One sometimes overlooked aspect when comparing across languages is the difference in timing due to maily to differences in the random number generators. The implementation in R is of very high quality, but does not aim to be the fastest possible generator. For example, when we compared different approaches for a simple Gibbs sampler, it was seen that RBG accounted for a large proportion of the difference between and Rcpp implementation in C++, using R’s RNG, and a GSL-based C implementation.
Here we are comparing three approaches: Armadillo, GSL and R.
We start with the generator in Armadillo.
We can also use the GSL.
Last, we look at the generator in R.
And we can compare the approaches.
test replications elapsed relative 3 armaNormal(1e+06) 100 8.355 1.000 1 rcppNormal(1e+06) 100 12.117 1.450 2 gslNormal(1e+06) 100 14.906 1.784
Here we find the speed of the Rcpp generator to be slightly ahead of the GSL generator, but both are dominated by the one in Armadillo.
Of course, speed is not the only consideration. Rcpp still allows us to generate the same random numbers as R itself which is valuable.Tweet