[Rd] Fast way to call an R function from C++?

Iñaki Ucar |uc@r @end|ng |rom |edor@project@org
Tue Jun 18 20:39:16 CEST 2019


For reference, your benchmark using UNWIND_PROTECT:

> system.time(test(testFunc, evn$x))
   user  system elapsed
  0.331   0.000   0.331
> system.time(test(C_test1, testFunc, evn$x))
   user  system elapsed
  2.029   0.000   2.036
> system.time(test(C_test2, expr, evn))
   user  system elapsed
  2.307   0.000   2.313
> system.time(test(C_test3, testFunc, evn$x))
   user  system elapsed
  2.131   0.000   2.138

Iñaki

On Tue, 18 Jun 2019 at 20:35, Iñaki Ucar <iucar using fedoraproject.org> wrote:
>
> On Tue, 18 Jun 2019 at 19:41, King Jiefei <szwjf08 using gmail.com> wrote:
> >
> > [...]
> >
> > It is clear to see that calling an R function in R is the fast one, it is
> > about 5X faster than ` R_forceAndCall ` and ` Rf_eval`. the latter two
> > functions have a similar performance and using Rcpp is the worst one. Is it
> > expected? Why is calling an R function from C++ much slower than calling
> > the function from R? Is there any faster way to do the function call in C++?
>
> Yes, there is: enable fast evaluation by setting
> -DRCPP_USE_UNWIND_PROTECT, or alternatively, use
>
> // [[Rcpp::plugins(unwindProtect)]]
>
> Iñaki



-- 
Iñaki Úcar



More information about the R-devel mailing list