Compile times Rcpp11 vs Rcpp

May 22, 2014
By

(This article was first published on R Enthusiast and R/C++ hero, and kindly contributed to R-bloggers)

So I've been curious about a different kind of performance comparison between Rcpp11 and Rcpp, i.e. I've benchmarked the time it takes to compile the following code (the example you get from RStudio when you do new C++ file) with Rcpp and Rcpp11.

#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
int timesTwo(int x) {  
   return x * 2;
}

We'll compare Rcpp::sourceCpp and attributes::sourceCpp. They both generate essentially the same decoration code.

require(microbenchmark)  
compile_Rcpp <- function(){  
  Rcpp::sourceCpp("/tmp/timesTwo.cpp", rebuild = TRUE )
}
compile_Rcpp11 <- function(){  
  attributes::sourceCpp( "/tmp/timesTwo.cpp" )
}

These timings come from my iMac running Mavericks.

> microbenchmark( Rcpp = compile_Rcpp(), Rcpp11 = compile_Rcpp11(), times = 10 )
Unit: seconds  
   expr      min       lq   median       uq      max neval
   Rcpp 3.061308 3.068119 3.069977 3.071560 3.258582    10
 Rcpp11 1.475950 1.479628 1.480901 1.485374 1.512100    10

This is interesting. Twice as fast, although this has not been a goal, this is still nice to have, nobody likes waiting for the compiler more than needed. I'll probably produce more benchmarks with various code examples and various compilers for the article.

Rcpp11 is much smaller in terms of size of the code base (the number of lines in the various header files), and I think these benchmark show us the consequence of that. Less code to #include yields better performance. Sweet.

To leave a comment for the author, please follow the link and comment on his blog: R Enthusiast and R/C++ hero.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.