[Rcpp-devel] Rcpp speed
Gabor Grothendieck
ggrothendieck at gmail.com
Tue Dec 21 15:15:12 CET 2010
Can anyone explain these results? Rcpp takes 30% more time than R
with 10 elements, the same time as R with 1000 elements and 7x as long
with a million elements. I would have expected the ratio to be
highest for `10 elements since that would be dominated by the call
sequence but its the other way around and it seems to get relatively
less efficient as the size of the vector grows.
> require(inline)
> testfun <- cxxfunction(signature(x="numeric", y="numeric"),
+ body = '
+ NumericVector xx(x);
+ NumericVector yy(y);
+ NumericVector zz = xx + yy;
+ return( zz );
+ ', plugin="Rcpp")
> x <- 1:3
> y <- 10 * x
> testfun(x, y)
[1] 11 22 33
>
> library(rbenchmark)
> x <- 1:10
> benchmark(replications = 10000, R = x + x, Rcpp = testfun(x, x))
test replications elapsed relative user.self sys.self user.child sys.child
1 R 10000 0.17 1.000000 0.16 0 NA NA
2 Rcpp 10000 0.22 1.294118 0.23 0 NA NA
>
> x <- 1:1000
> benchmark(R = x + x, Rcpp = testfun(x, x))
test replications elapsed relative user.self sys.self user.child sys.child
1 R 100 0.00 0 0.00 0 NA NA
2 Rcpp 100 0.01 1 0.01 0 NA NA
>
> x <- 1:1000000
> benchmark(R = x + x, Rcpp = testfun(x, x))
test replications elapsed relative user.self sys.self user.child sys.child
1 R 100 2.34 1.000000 1.81 0.15 NA NA
2 Rcpp 100 16.64 7.111111 12.63 1.66 NA NA
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the Rcpp-devel
mailing list