Le 04/01/11 16:35, Andrew Redd a écrit :
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

Hmmm. I suspect someone might be able to speed up "sum". Essentially it contains lots of tests for NA that might be expensive if none of the input data is NA.

Not sure I want to be that someone just yet.

On Tue, Jan 4, 2011 at 8:14 AM, Cedric Ginestet
<c.gineste...@googlemail.com <mailto:c.gineste...@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


--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/fT2rZM : highlight 0.2-5
|- http://bit.ly/gpCSpH : Evolution of Rcpp code size
`- http://bit.ly/hovakS : RcppGSL initial release


_______________________________________________
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

Reply via email to