TheProfitTable / loanportr

Loan portfolio analysis with R
5 stars 5 forks source link

Introduce rcpp #25

Open NaasvanH opened 6 years ago

NaasvanH commented 6 years ago

Background

There is a need to make the functions in the package faster and more scalable. One alternative is to investigate the use of Rcpp.
Read this section of the R packages book for background.

Objective

The objective is to add a c++ version of a function to the package using Rcpp. Not necessarily for the sake of optimisation, but to learn and prove how the process works.
Pick a simple function that won't take much work.
Document and include the function using the workflow described in the R packages book (link above in Background) Write a Rcpp version of it (use a branch to make the changes to the package)

DandeVilliers commented 6 years ago

Branch Introduce-rcpp-issue-#25 introduces a c++ version of add_perc() named add_perc_cpp().

Since the function is called within vardistr_perc(), a new boolean parameter was introduced (use_cpp) to have the capability to switch between the c++ version and pure R. By default vardistr_perc() will run with c++ enabled.

Microbenchmark tests indicate a 10-35% speed improvement over the pure R add_perc function.