Cedric,<div>This was addressed about 2 weeks ago on the list, please read the archives. Basic point, Rcpp/sugar will not be faster than basic functions in R. Do something more complicated to see improvements. I would suggest something that involves lots of copies and edits, that will mess with R's memory management but be much more efficient in compiled code.</div>
<div><br></div><div>-Andrew<br><br><div class="gmail_quote">On Tue, Jan 4, 2011 at 8:14 AM, Cedric Ginestet <span dir="ltr"><<a href="mailto:c.ginestet05@googlemail.com">c.ginestet05@googlemail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div text="#000000" bgcolor="#ffffff">
Happy new year to everyone, <br>
<br>
I have made a very straightforward comparison of the performance of
standard R, Rcpp function and sugar, and found that the latter
produces the poorest performance. Let me know what you think and how
I could improve such performance assessment. <br>
<br>
###################################################<br>
Summing1 <- cxxfunction(signature(x="numeric"), '<br>
NumericVector xV(x);<br>
double out = sum(xV);<br>
return wrap(out);<br>
',plugin="Rcpp")<br>
Summing2 <- cxxfunction(signature(x="numeric"), '<br>
NumericVector xV(x);<br>
double out = 0.0;<br>
for(int i=0; i<xV.size(); i++) out += xV[i]; <br>
return wrap(out);<br>
',plugin="Rcpp")<br>
###################################################<br>
# Results.<br>
n <- 1000000; x <- rnorm(n)<br>
Summing1(x); Summing2(x); sum(x)<br>
#######################<br>
gives: <br>
[1] -396.6129<br>
[1] -396.6129<br>
[1] -396.6129<br>
<br>
###################################################<br>
# Time.<br>
system.time(Summing1(x)); # Sugar<br>
system.time(Summing2(x)); # Rcpp<br>
system.time(sum(x)); # R-base<br>
###################<br>
> system.time(Summing1(x)); <br>
user system elapsed <br>
0.016 0.000 0.016 <br>
> system.time(Summing2(x));<br>
user system elapsed <br>
0.008 0.000 0.011 <br>
> system.time(sum(x));<br>
user system elapsed <br>
0.000 0.000 0.003 <br>
<br>
<br>
Sugar appears to be the slowest! What about Rcpp basic loop? Why
isn't as fast as the standard sum() in R-base? <br>
Cheers, <br>
Cedric <br>
<br>
<div>-- <br>
<div><font face="Times" size="3">
Cedric Ginestet <br>
Centre for Neuroimaging Sciences (L3.04) <br>
NIHR Biomedical Research Centre <br>
Institute of Psychiatry, Box P089 <br>
Kings College London <br>
De Crespigny Park<br>
London <br>
SE5 8AF <br>
<br>
</font>
</div>
</div>
</div>
<br>_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">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" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
<br></blockquote></div><br></div>