| Start |
|---|
| Speeding tough-to-vectorize for loops with Rcpp Consider the following tough-to-vectorize for loop, which creates a vector of length This code involves a for loop with a fast operation ( One possible approach to speeding this function would be to implement it in C++, using the Rcpp package: This often provides significant speedups for large computations while yielding the exact same results: In this case, the Rcpp code generates a vector of length 1 million in 0.03 seconds instead of 1.31 seconds with the base R approach. |
| Speeding tough-to-vectorize for loops by byte compiling Following the Rcpp example in this documentation entry, consider the following tough-to-vectorize function, which creates a vector of length One simple approach to speeding up such a function without rewriting a single line of code is byte compiling the code using the R compile package: The resulting function will often be significantly faster while still returning the same results: In this case, byte compiling sped up the tough-to-vectorize operation on a vector of length 1 million from 1.20 seconds to 0.34 seconds. Remark The essence of
|
Read Article
https://develop.horje.com/learn/1434/reference