I use Rcpp and RcppArmadillo and i have a "strange" problem. Lets say that i have function f1(). I include this function inside my package and run the command "R CMD INSTALL". After it's done i run a benchmark and i realise that f1 is slower about 100 microseconds inside the package than outside. So if a function wants 100ms to finish, in the package wants about 200+ms.
Code:
functions.cpp
vec f1(vec x){
vec F( x.size() );
for( int i = 0; i < x.size(); ++i ){
// do something
}
return F;
}
exportfunctions.cpp
vec f1(vec x);
RcppExport SEXP MyPackage_f1(SEXP xSEXP) {
BEGIN_RCPP
RObject __result;
RNGScope __rngScope;
traits::input_parameter< vec >::type x(xSEXP);
__result = wrap(f1(x));
return __result;
END_RCPP
}
exportfunctions.R
f1<- function(x) {
.Call( ' MyPackage_f1 ' , PACKAGE = ' MyPackage ', x )
}
An example of how my code is been written. I believe the problem is that a function.R calls a function.cpp wich calls the final function. But why is this happening inside the package and not in sourceCpp. I can't understand the difference.