<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body 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 class="moz-signature">-- <br>
<div class="moz-signature"><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>
</body>
</html>