Here's an updated version of the Rcpp code with a single call: https://github.com/jesusfv/Comparison-Programming-Languages-Economics/compare/master...kylebmetrum:master
The comparison runs are here: https://github.com/kylebmetrum/Comparison-Programming-Languages-Economics/issues/1 For typical a single run .... Original Rcpp: 2.762 New Rcpp: 0.878 testclang: 0.686582 Original Rcpp / testclang: 4.026239 New Rcpp / testclang: 1.279883 Moving sourceCpp was a big improvement as suggested. Also, changing from parens to brackets to access NumericVector sped things up. And some improvement too from re-factoring so that there was just a single call to the compiled code. Kyle On Mon, Sep 24, 2018 at 2:24 AM Iñaki Ucar <iu...@fedoraproject.org> wrote: > > > El dom., 23 sept. 2018 13:01, Iñaki Ucar <iu...@fedoraproject.org> > escribió: > >> Also you can try adding >> >> // [[Rcpp::plugins(unwindProtect)]] >> >> to InsideLoop.cpp. That should boost the performance too with the >> latest version of Rcpp. >> > > Taking a look now, and I realize there are just calls to C++, not to R. > So, please, forget about what I've said. The dangers of skimming through > code in a mobile device and speaking too soon. > > Iñaki > > >> Iñaki > > >> El dom., 23 sept. 2018 a las 12:46, Kyle Baron (<ky...@metrumrg.com>) >> escribió: >> > >> > >> > I got mOutput mixed up with mResults in the last message; it mResults >> that gets created up front and then every iteration. >> > >> > >> https://github.com/jesusfv/Comparison-Programming-Languages-Economics/blob/master/RBC_Rcpp.R#L45 >> > >> https://github.com/jesusfv/Comparison-Programming-Languages-Economics/blob/master/InsideLoop.cpp#L12 >> > >> > >> > >> > >> > >> > On Sun, Sep 23, 2018 at 5:38 AM Kyle Baron <ky...@metrumrg.com> wrote: >> >> >> >> >> >> It seems like the sourceCpp thing is the biggie. That dropped about a >> second of the time from something like 2.7 to 1.7 seconds >> >> >> >> They also create mOutput and then re-create it every time it goes into >> InsideLoop >> >> >> https://github.com/jesusfv/Comparison-Programming-Languages-Economics/blob/master/RBC_Rcpp.R#L41 >> >> >> https://github.com/jesusfv/Comparison-Programming-Languages-Economics/blob/master/InsideLoop.cpp#L12 >> >> >> >> I just passed mOutput into InsideLoop and modified it there >> >> >> https://github.com/kylebmetrum/Comparison-Programming-Languages-Economics/commit/89015a72a0cf673739e83e38d4a545db4886b879 >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> On Sat, Sep 22, 2018 at 1:21 PM Dirk Eddelbuettel <e...@debian.org> >> wrote: >> >>> >> >>> >> >>> On 22 September 2018 at 12:36, Michael Weylandt wrote: >> >>> | I don't have time right now, but the offending line is here: >> >>> | >> >>> | >> https://github.com/jesusfv/Comparison-Programming-Languages-Economics/blob/master/RBC_Rcpp.R#L62 >> >>> | >> >>> | which calls `sourceCpp` repeatedly on each loop iteration. >> >>> | >> >>> | Should be a one line change to move it outside the loop and >> un-sully the >> >>> | good name of Rcpp. >> >>> >> >>> Nice catch!! You should _definitely_ send him a PR. I also suggest >> to move >> >>> the sourceCpp() outside the timed segment as I do not think he >> accounts for >> >>> compilation in the other approaches (eg C++). >> >>> >> >>> Dirk >> >>> >> >>> -- >> >>> http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org >> >>> _______________________________________________ >> >>> Rcpp-devel mailing list >> >>> Rcpp-devel@lists.r-forge.r-project.org >> >>> >> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel >> >> >> >> >> >> >> >> >> > _______________________________________________ >> > Rcpp-devel mailing list >> > Rcpp-devel@lists.r-forge.r-project.org >> > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel >> >> >> >> -- >> Iñaki Ucar >> >
_______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel