Skip to content
Prev 9324 / 10988 Next

[Rcpp-devel] Alternative way of calling R functions within C++

Dirk, good point. This is a very simple function and if I add complexity at
the end there's no significant difference between calling -fun-,
-cppFuncall- and -RcppFuncall-. Just to make this thread more complete, if
I modify -fun- from

fun <- function(x) {
  -cos(x[1])*cos(x[2])*exp(-((x[1] - pi)^2 + (x[2] - pi)^2))
}

to

fun <- function(x) {
  w<-sapply(1:1e3,function(x) -cos(x[1])*cos(x[2])*exp(-((x[1] - pi)^2 +
(x[2] - pi)^2)))
  1
}

Running the benchmark I get

Unit: relative
                expr min lq     mean median uq max neval
  cppFuncall(x, fun)   1  1 1.044215      1  1 6.1  1000
 RcppFuncall(x, fun)   1  1 1.018957      1  1 2.7  1000
              fun(x)   1  1 1.000000      1  1 1.0  1000

Which is way more reasonable from what I was getting at first. No
significant difference overall.

Kevin, thanks for the example, now I get why isn't a good idea! This has
been very useful to me.

Best,

George G. Vega Yon
+1 (626) 381 8171
http://www.its.caltech.edu/~gvegayon/
On Wed, Aug 3, 2016 at 12:34 PM, Kevin Ushey <kevinushey at gmail.com> wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20160803/c9144d9a/attachment.html>