[Rcpp-devel] Sugar seems slower than Rcpp.
Andrew Redd
amredd at gmail.com
Tue Jan 4 16:35:58 CET 2011
Cedric,
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.
-Andrew
On Tue, Jan 4, 2011 at 8:14 AM, Cedric Ginestet <c.ginestet05 at googlemail.com
> wrote:
> Happy new year to everyone,
>
> 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.
>
> ###################################################
> Summing1 <- cxxfunction(signature(x="numeric"), '
> NumericVector xV(x);
> double out = sum(xV);
> return wrap(out);
> ',plugin="Rcpp")
> Summing2 <- cxxfunction(signature(x="numeric"), '
> NumericVector xV(x);
> double out = 0.0;
> for(int i=0; i<xV.size(); i++) out += xV[i];
> return wrap(out);
> ',plugin="Rcpp")
> ###################################################
> # Results.
> n <- 1000000; x <- rnorm(n)
> Summing1(x); Summing2(x); sum(x)
> #######################
> gives:
> [1] -396.6129
> [1] -396.6129
> [1] -396.6129
>
> ###################################################
> # Time.
> system.time(Summing1(x)); # Sugar
> system.time(Summing2(x)); # Rcpp
> system.time(sum(x)); # R-base
> ###################
> > system.time(Summing1(x));
> user system elapsed
> 0.016 0.000 0.016
> > system.time(Summing2(x));
> user system elapsed
> 0.008 0.000 0.011
> > system.time(sum(x));
> user system elapsed
> 0.000 0.000 0.003
>
>
> Sugar appears to be the slowest! What about Rcpp basic loop? Why isn't as
> fast as the standard sum() in R-base?
> Cheers,
> Cedric
>
> --
> Cedric Ginestet
> Centre for Neuroimaging Sciences (L3.04)
> NIHR Biomedical Research Centre
> Institute of Psychiatry, Box P089
> Kings College London
> De Crespigny Park
> London
> SE5 8AF
>
>
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110104/8c081de0/attachment-0001.htm>
More information about the Rcpp-devel
mailing list