Created
March 20, 2017 15:04
-
-
Save dfalbel/5caf65d2ed24bcd04c661bab04588a6a to your computer and use it in GitHub Desktop.
parallel_sort
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
Rcpp::sourceCpp('t.cpp') | |
x <- runif(1000000) | |
m <- microbenchmark::microbenchmark( | |
psort(x), | |
csort(x), | |
sort(x) | |
) | |
x <- 1000000:1 | |
m <- microbenchmark::microbenchmark( | |
psort(x), | |
csort(x), | |
sort(x) | |
) |
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
// [[Rcpp::depends(RcppParallel)]] | |
#include <Rcpp.h> | |
#include <RcppParallel.h> | |
using namespace Rcpp; | |
// This is a simple example of exporting a C++ function to R. You can | |
// source this function into an R session using the Rcpp::sourceCpp | |
// function (or via the Source button on the editor toolbar). Learn | |
// more about Rcpp at: | |
// | |
// http://www.rcpp.org/ | |
// http://adv-r.had.co.nz/Rcpp.html | |
// http://gallery.rcpp.org/ | |
// | |
// [[Rcpp::export]] | |
NumericVector psort(NumericVector x) { | |
NumericVector y = clone(x); | |
tbb::parallel_sort(y.begin(), y.end()); | |
return y; | |
} | |
// [[Rcpp::export]] | |
NumericVector csort(NumericVector x) { | |
NumericVector y = clone(x); | |
std::sort(y.begin(), y.end()); | |
return y; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment