Rcpp Version 1.0.9
performance.R
Go to the documentation of this file.
1 
2 require( inline )
3 require( Rcpp )
4 
5 expressions <- list(
6  times = "x * y" ,
7  plus = "x + y"
8 # ,
9 # minus = "x - y",
10 # divides = "x / y",
11 # exp_ = "exp( x )"
12 )
13 
14 signatures <- lapply( expressions, function(.) signature( x_ = "numeric", y_ = "numeric", n_ = "integer" ) )
15 bodies <- lapply( expressions, function(.){
16  sprintf( '
17  int n = as<int>( n_ ) ;
18  NumericVector x(x_), y(y_), z(x.size()) ;
19  for( int i=0; i<n; i++){
20  z = %s ;
21  }
22  return z ;
23 ', . )
24 } )
25 
26 fx <- cxxfunction( signatures, bodies, plugin = "Rcpp" )
27 
28 set.seed( 43231 )
29 x <- runif( 100000, min = 1, max = 100)
30 y <- runif( 100000, min = 1, max = 100)
31 # resolving the dyn lib once
32 invisible( lapply( fx, function(f){ f( x, y, 1L) } ) )
33 
34 # t( sapply( fx, function(f){
35 # system.time( f( x, y, 10000 ) )
36 # } ) )[, 1:3]
37 #
38