[Rcpp-devel] Rcpp_fast_eval
Kevin Ushey
kevinushey at gmail.com
Sun Jun 10 02:15:37 CEST 2018
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:
> system.time(Rcpp_eval_old(quote(1 + 1), 1E5L))
user system elapsed
1.198 0.003 1.203
> system.time(Rcpp_eval_new(quote(1 + 1), 1E5L))
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:
> 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
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20180609/43cad21c/attachment.html>
More information about the Rcpp-devel
mailing list