<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Here's an updated version of the Rcpp code with a single call:</div><div class="gmail_default"><a href="https://github.com/jesusfv/Comparison-Programming-Languages-Economics/compare/master...kylebmetrum:master">https://github.com/jesusfv/Comparison-Programming-Languages-Economics/compare/master...kylebmetrum:master</a><br></div><div class="gmail_default"><br></div><div class="gmail_default">The comparison runs are here:</div><div class="gmail_default"><a href="https://github.com/kylebmetrum/Comparison-Programming-Languages-Economics/issues/1">https://github.com/kylebmetrum/Comparison-Programming-Languages-Economics/issues/1<br></a></div><div class="gmail_default"><br></div><div class="gmail_default">For typical a single run .... </div><div class="gmail_default"><br></div><div class="gmail_default">Original Rcpp: 2.762<br></div><div class="gmail_default">New Rcpp: <span style="background-color:rgb(246,248,250);color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:11.9px">0.878</span></div><div class="gmail_default"><span style="background-color:rgb(246,248,250);color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:11.9px">testclang: </span><span style="background-color:rgb(246,248,250);color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:11.9px">0.686582</span></div><div class="gmail_default"><span style="background-color:rgb(246,248,250);color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:11.9px"><br></span></div><div class="gmail_default"><span style="background-color:rgb(246,248,250);color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:11.9px"><br></span></div><div class="gmail_default"><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace"><span style="font-size:11.9px;background-color:rgb(246,248,250)">Original Rcpp / testclang: </span><span style="font-size:11.9px">4.026239</span></font></div><div class="gmail_default"><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace"><span style="font-size:11.9px">New Rcpp / testclang: 1.279883</span></font></div><div class="gmail_default"><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace"><span style="font-size:11.9px"><br></span></font></div><div class="gmail_default"><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace"><span style="font-size:11.9px">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 </span></font></div><div class="gmail_default"><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace"><span style="font-size:11.9px">single call to the compiled code.</span></font></div><div class="gmail_default"><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace"><span style="font-size:11.9px"><br></span></font></div><div class="gmail_default">Kyle</div><div class="gmail_default"><span style="background-color:rgb(246,248,250);color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:11.9px"><br></span></div><div class="gmail_default"><br></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Sep 24, 2018 at 2:24 AM Iñaki Ucar <<a href="mailto:iucar@fedoraproject.org">iucar@fedoraproject.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr">El dom., 23 sept. 2018 13:01, Iñaki Ucar <<a href="mailto:iucar@fedoraproject.org" target="_blank">iucar@fedoraproject.org</a>> escribió:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Also you can try adding<br>
<br>
// [[Rcpp::plugins(unwindProtect)]]<br>
<br>
to InsideLoop.cpp. That should boost the performance too with the<br>
latest version of Rcpp.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">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.</div><div dir="auto"><br></div><div dir="auto">Iñaki</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Iñaki</blockquote></div></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
El dom., 23 sept. 2018 a las 12:46, Kyle Baron (<<a href="mailto:kyleb@metrumrg.com" rel="noreferrer" target="_blank">kyleb@metrumrg.com</a>>) escribió:<br>
><br>
><br>
> I got mOutput mixed up with mResults in the last message; it mResults that gets created up front and then every iteration.<br>
><br>
> <a href="https://github.com/jesusfv/Comparison-Programming-Languages-Economics/blob/master/RBC_Rcpp.R#L45" rel="noreferrer noreferrer" target="_blank">https://github.com/jesusfv/Comparison-Programming-Languages-Economics/blob/master/RBC_Rcpp.R#L45</a><br>
> <a href="https://github.com/jesusfv/Comparison-Programming-Languages-Economics/blob/master/InsideLoop.cpp#L12" rel="noreferrer noreferrer" target="_blank">https://github.com/jesusfv/Comparison-Programming-Languages-Economics/blob/master/InsideLoop.cpp#L12</a><br>
><br>
><br>
><br>
><br>
><br>
> On Sun, Sep 23, 2018 at 5:38 AM Kyle Baron <<a href="mailto:kyleb@metrumrg.com" rel="noreferrer" target="_blank">kyleb@metrumrg.com</a>> wrote:<br>
>><br>
>><br>
>> 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<br>
>><br>
>> They also create mOutput and then re-create it every time it goes into InsideLoop<br>
>> <a href="https://github.com/jesusfv/Comparison-Programming-Languages-Economics/blob/master/RBC_Rcpp.R#L41" rel="noreferrer noreferrer" target="_blank">https://github.com/jesusfv/Comparison-Programming-Languages-Economics/blob/master/RBC_Rcpp.R#L41</a><br>
>> <a href="https://github.com/jesusfv/Comparison-Programming-Languages-Economics/blob/master/InsideLoop.cpp#L12" rel="noreferrer noreferrer" target="_blank">https://github.com/jesusfv/Comparison-Programming-Languages-Economics/blob/master/InsideLoop.cpp#L12</a><br>
>><br>
>> I just passed mOutput into InsideLoop and modified it there<br>
>> <a href="https://github.com/kylebmetrum/Comparison-Programming-Languages-Economics/commit/89015a72a0cf673739e83e38d4a545db4886b879" rel="noreferrer noreferrer" target="_blank">https://github.com/kylebmetrum/Comparison-Programming-Languages-Economics/commit/89015a72a0cf673739e83e38d4a545db4886b879</a><br>
>><br>
>><br>
>><br>
>><br>
>><br>
>><br>
>><br>
>><br>
>><br>
>><br>
>><br>
>> On Sat, Sep 22, 2018 at 1:21 PM Dirk Eddelbuettel <<a href="mailto:edd@debian.org" rel="noreferrer" target="_blank">edd@debian.org</a>> wrote:<br>
>>><br>
>>><br>
>>> On 22 September 2018 at 12:36, Michael Weylandt wrote:<br>
>>> | I don't have time right now, but the offending line is here:<br>
>>> |<br>
>>> | <a href="https://github.com/jesusfv/Comparison-Programming-Languages-Economics/blob/master/RBC_Rcpp.R#L62" rel="noreferrer noreferrer" target="_blank">https://github.com/jesusfv/Comparison-Programming-Languages-Economics/blob/master/RBC_Rcpp.R#L62</a><br>
>>> |<br>
>>> | which calls `sourceCpp` repeatedly on each loop iteration.<br>
>>> |<br>
>>> | Should be a one line change to move it outside the loop and un-sully the<br>
>>> | good name of Rcpp.<br>
>>><br>
>>> Nice catch!! You should _definitely_ send him a PR. I also suggest to move<br>
>>> the sourceCpp() outside the timed segment as I do not think he accounts for<br>
>>> compilation in the other approaches (eg C++).<br>
>>><br>
>>> Dirk<br>
>>><br>
>>> --<br>
>>> <a href="http://dirk.eddelbuettel.com" rel="noreferrer noreferrer" target="_blank">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org" rel="noreferrer" target="_blank">edd@debian.org</a><br>
>>> _______________________________________________<br>
>>> Rcpp-devel mailing list<br>
>>> <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" rel="noreferrer" target="_blank">Rcpp-devel@lists.r-forge.r-project.org</a><br>
>>> <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" rel="noreferrer noreferrer" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
>><br>
>><br>
>><br>
>><br>
> _______________________________________________<br>
> Rcpp-devel mailing list<br>
> <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" rel="noreferrer" target="_blank">Rcpp-devel@lists.r-forge.r-project.org</a><br>
> <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" rel="noreferrer noreferrer" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
<br>
<br>
<br>
-- <br>
Iñaki Ucar<br>
</blockquote></div></div></div>
</blockquote></div><br clear="all"><div><br></div><br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"></div></div></div>