Created
April 3, 2017 11:21
-
-
Save nathan-russell/1c0e18d517d54d9c4197aeae2de58b08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Rcpp.h> | |
using namespace Rcpp; | |
// [[Rcpp::export]] | |
IntegerVector rcpp_build(int n) | |
{ | |
IntegerVector res; | |
for (int i = 0; i < n; i++) { | |
res.push_back(i); | |
} | |
return res; | |
} | |
// [[Rcpp::export]] | |
IntegerVector stl_build(int n) | |
{ | |
std::vector<int> res; | |
for (int i = 0; i < n; i++) { | |
res.push_back(i); | |
} | |
return wrap(res); | |
} | |
/*** R | |
microbenchmark::microbenchmark( | |
"Rcpp" = rcpp_build(1e4), | |
"STL" = stl_build(1e4), | |
times = 200L | |
) | |
# Unit: microseconds | |
# expr min lq mean median uq max neval cld | |
# Rcpp 74293.567 76430.353 89823.14842 77650.885 79364.228 209266.312 200 b | |
# STL 30.789 37.631 70.79363 65.379 71.271 1672.862 200 a | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment