[Rcpp-devel] R.e. First foray into Rcpp and comparison of speed with R

Darren Cook darren at dcook.org
Fri Sep 2 02:21:57 CEST 2011


> I see a huge difference in this set of
> examples ( which are painfully repetitive on many levels)
> that are identical except for [] vs. (). This is true whether
> or not ret appears on the RHS. Am I missing something here?

That matches what the source says, e.g. Rcpp/include/Rcpp/vector/Vector.h:

  inline Proxy operator[]( int i ){ return cache.ref(i) ; }
  inline Proxy operator()( const size_t& i) throw(index_out_of_bounds){
		return cache.ref( offset(i) ) ;

The offset() call checks that i is within range. So, for your artificial
example that is most of the effort.

(Just seen Dirk's reply; I think what may be going on is that
cache.ref(i) may get optimized to end up as a single pointer
dereference, but the function call to offset() is too complex, so it
ends up not even getting inlined.)

Darren


-- 
Darren Cook, Software Researcher/Developer

http://dcook.org/work/ (About me and my work)
http://dcook.org/blogs.html (My blogs and articles)


More information about the Rcpp-devel mailing list