Skip to content
Back to formatted view

Raw Message

Message-ID: <CAGkGB64q+HxiU3pNT4_RGjYFsoX=KuEXv5D2q8RhoXBB_TzCFg@mail.gmail.com>
Date: 2017-02-21T11:12:40Z
From: Eridk Poliruyt
Subject: [Rcpp-devel] Slower sugar functions through Rcpp than R?

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>