An Observation
For medium-size matrices, the overheads on passing matrices from R to C++ are massively slower for arma::mat
types than for
I believe this creates a new Armadillo matrix then copies the contents of your numeric matrix.
To cast the NumericMatrix to type arma::mat, you should use the following:
// [[Rcpp::export]]
double test_const_arma( const mat& X ) {
return 0.0 ;
}
Speed comparison on my machine:
microbenchmark( test_const_arma( XX ), test_nm( XX ), test_arma( XX ), test_nm_conv( XX ))
## Unit: microseconds
## expr min lq mean median uq max neval
## test_const_arma(XX) 1.852 2.381 3.69014 2.7885 4.3490 11.994 100
## test_nm(XX) 1.925 2.455 3.47679 2.8535 3.5195 21.222 100
## test_arma(XX) 68.593 71.212 83.63055 73.4555 98.8070 278.981 100
## test_nm_conv(XX) 68.700 70.983 80.55983 73.1705 82.2665 183.484 100