Skip to content

[Rcpp-devel] Rcpp_fast_eval

2 messages · Iñaki Ucar, Kevin Ushey

#
Hi all,

I've followed with interest the development of the new evaluation API.
Now that it's finally merged, I was testing it. Perhaps I'm mistaken,
but shouldn't we expect a performance improvement in code such as the
following?

Rcpp::sourceCpp(code='
  #include <Rcpp.h>
  using namespace Rcpp;

  // [[Rcpp::export]]
  void old_api(Function func, int n) {
    for (int i=0; i<n; i++) func();
  }'
)

Rcpp::sourceCpp(code='
  #define RCPP_PROTECTED_EVAL
  #include <Rcpp.h>
  using namespace Rcpp;

  // [[Rcpp::export]]
  void new_api(Function func, int n) {
    for (int i=0; i<n; i++) func();
  }'
)

func <- function() 1
system.time(old_api(func, 1e5))
system.time(new_api(func, 1e5))

Regards,
I?aki
#
I think this is mostly because we still haven't ported the majority of
usages of Rcpp_eval() to the new Rcpp_fast_eval(), so by default users are
still getting the slower Rcpp_eval(). Compare e.g.

Rcpp::sourceCpp(code='
  #include <Rcpp.h>
  using namespace Rcpp;

  // [[Rcpp::export]]
  void Rcpp_eval_old(SEXP expr, int n) {
    for (int i = 0; i < n; i++)
      Rcpp_eval(expr, R_GlobalEnv);
  }'
)

Rcpp::sourceCpp(code='
  #define RCPP_PROTECTED_EVAL
  #include <Rcpp.h>
  using namespace Rcpp;

  // [[Rcpp::export]]
  void Rcpp_eval_new(SEXP expr, int n) {
    for (int i = 0; i < n; i++)
       Rcpp_fast_eval(expr, R_GlobalEnv);
  }')

system.time(Rcpp_eval_old(quote(1 + 1), 1E5L))
system.time(Rcpp_eval_new(quote(1 + 1), 1E5L))


I get:
user  system elapsed
  1.198   0.003   1.203
user  system elapsed
  0.118   0.034   0.151


We'll take a closer look next week.
On Sat, Jun 9, 2018 at 4:40 AM I?aki ?car <i.ucar86 at gmail.com> wrote:

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