[Rcpp-devel] Sugar seems slower than Rcpp.

Dirk Eddelbuettel edd at debian.org
Tue Jan 4 16:37:02 CET 2011


On 4 January 2011 at 15:14, Cedric Ginestet 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?

1)  Try to think a about measurement error here; these times are all minuscule.

2)  Consider reading the list archive, we have better use of benchmarks using
    rbenchmark and replications; these are also some example in the examples
    right in Rcpp

3)  Consider reading the list archive and discussions about the NoNA tests.

4)  Lastly, consider Romain's point about a baseline using an empty function. 

Dirk 


| 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

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list