Created
April 4, 2018 01:08
-
-
Save hrbrmstr/276072b0a83ee25328aaa1c046880ce8 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
Rcpp::cppFunction('int rcpp_find2(NumericVector needle, NumericVector haystack) { | |
NumericVector::iterator it; | |
it = std::search(haystack.begin(), haystack.end(), needle.begin(), needle.end()); | |
int pos = it - haystack.begin() + 1; | |
if (pos > haystack.size()) pos = -1; | |
return(pos); | |
}') | |
set.seed(010) | |
haystack <- sample(0:12, size = 2000, replace = TRUE) | |
needle <- c(2L, 0L, 9L) | |
microbenchmark::microbenchmark(rcpp_find2(needle, haystack)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment