Compile times Rcpp11 vs Rcpp

[This article was first published on R Enthusiast and R/C++ hero, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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 their blog: R Enthusiast and R/C++ hero.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)