Rcpp Version 1.0.14
Loading...
Searching...
No Matches
performance.R
Go to the documentation of this file.
1
2require( inline )
3require( Rcpp )
4
5expressions <- list(
6 times = "x * y" ,
7 plus = "x + y"
8# ,
9# minus = "x - y",
10# divides = "x / y",
11# exp_ = "exp( x )"
12)
13
14signatures <- lapply( expressions, function(.) signature( x_ = "numeric", y_ = "numeric", n_ = "integer" ) )
15bodies <- 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
26fx <- cxxfunction( signatures, bodies, plugin = "Rcpp" )
27
28set.seed( 43231 )
29x <- runif( 100000, min = 1, max = 100)
30y <- runif( 100000, min = 1, max = 100)
31# resolving the dyn lib once
32invisible( 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