system.time(old_api(func, 1e5))
user system elapsed
1.025 0.000 1.025
system.time(new_api(func, 1e5))
user system elapsed
0.025 0.000 0.025
I believe this is what Inaki expected.
Best wishes,
Qiang Kou
On Sat, Jun 9, 2018 at 8:15 PM, Kevin Ushey <kevinushey at gmail.com> wrote:
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