[Rcpp-devel] Slower sugar functions through Rcpp than R?

Eridk Poliruyt ep19772 at gmail.com
Tue Feb 21 12:12:40 CET 2017


Hi all,

I am just starting using Rcpp to accelerate some computations. I need to
evaluate some likelihood using common math functions like beta, lbeta,
gamma, lgamma, choose, lchoose, etc. But I found that it could be even
slower in Rcpp than R? Please see the example below using Rcpp..

// [[Rcpp::export]]
NumericVector gm(NumericVector& v1)
{
  return(gamma(v1));
}

In R, I compared the calculation with R as follows,
> microbenchmark(gm(1:10),gamma(1:10))
Unit: nanoseconds
        expr  min   lq    mean median   uq   max neval
    gm(1:10) 1510 1510 1854.26   1812 1812 13282   100
 gamma(1:10)  604  605  776.65    906  906  2114   100

May I ask is this normal and how can I speed up the calculation here?

Many thanks!
Eridk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20170221/99968b4a/attachment.html>


More information about the Rcpp-devel mailing list