[Rcpp-devel] Question on performance

Georgi Boshnakov georgi.boshnakov at manchester.ac.uk
Sat Sep 22 11:18:01 CEST 2018


Hi,

I don’t see any code going with the revised version, but
looking at the code coming with the original paper, see  http://economics.sas.upenn.edu/~jesusfv/RBC_codes.zip,
the following points come up:

1)There is no Rcpp code, so there is no way to verify the claims about Rcpp.

2)It is not at all obvious that the comparison is about computation – the following chunk for diagnostic printing is inside a double for loop (this is the .R version):

===
  iteration = iteration+1;
  if ((iteration %% 10)==0 | iteration ==1){
    cat("  Iteration = ", iteration," Sup Diff = ", maxDifference,"\n");
  }

===

Printing to the R console may well take significant proportion of the time.


3)The R version is a direct translation of the cpp version. This in itself is not a fair comparison. Moreover, note that the snipped in the cpp version of the above chunk uses the ‘||’ operator, while the R chunk above for some reason uses the ‘|’ operator, so the second condition in the ‘if’ statement is executed at every iteration.

4)The assignments of the data are done at compile time, while in R at execution time. Moreover there are man redundant operations in the R code,  eg  unnecessary conversions by as.matrix in the R code, which are absent in the cpp code.

5)The cpp function is for fixed data. Hence, the compilation and linking time need to be added to the overall time.

In summary, I would say that these results show, at best, that if a C++ function is converted to an interpreted language it will be slower, hardly  surprising. The exact timings do not seem relevant since they mix computation and output. There is also evidence that the authors have been more careful with their C++ code than the R code (I haven’t looked at the others). The claim about Rcpp is completely unverifiable. Moreover, for a fixed task, the time with the C++ executable should have included compilation, linking and invoking the executable.

I would ignore these comparisons and look at more reliable sources, such as examples by Dirk in the Rcpp package  and other materials and papers by him.


Georgi Boshnakov

From: Rcpp-devel [mailto:rcpp-devel-bounces at lists.r-forge.r-project.org] On Behalf Of Jordi Molins
Sent: 22 September 2018 08:03
To: rcpp-devel at lists.r-forge.r-project.org; Jordi Molins
Subject: [Rcpp-devel] Question on performance

Hello, I am new in this distribution list. I am using Rcpp for my project, and I enjoy the Rcpp implementation quite a lot.

I have read the paper https://www.sas.upenn.edu/~jesusfv/Update_March_23_2018.pdf and I see the performance of Rcpp is about 4x times slower than C++ proper code, or 3x times slower than Numba/Cython Python code.

Do you think that these figures are realistic? Of course, performance calculations are always dependent on many factors (very often, not explicit). But I am surprised that Rcpp is that slow in comparison to C++ code. I do not understand that Rcpp may be so slow, unless there are many calls back and forth between Rcpp and R. The same for compiled Python code vis a vis Rcpp.

Or maybe I am wrong?

Jordi Molins i Coronado
+34 69 38 000 59
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20180922/3373eb47/attachment-0001.html>


More information about the Rcpp-devel mailing list