[Rcpp-commits] r2147 - pkg/Rcpp/inst/examples/ConvolveBenchmarks

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Sep 23 17:48:59 CEST 2010


Author: romain
Date: 2010-09-23 17:48:59 +0200 (Thu, 23 Sep 2010)
New Revision: 2147

Modified:
   pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead.r
   pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead_1.cpp
   pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead_2.c
Log:
less C++ ioverhead if we register the symbol instead of doing extern C

Modified: pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead.r
===================================================================
--- pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead.r	2010-09-23 15:20:20 UTC (rev 2146)
+++ pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead.r	2010-09-23 15:48:59 UTC (rev 2147)
@@ -8,14 +8,20 @@
 dyn.load("overhead_1.so")
 dyn.load("overhead_2.so")
 
-overhead_c <- function(a,b) .Call( "overhead_c", a, b )
-overhead_cpp <- function(a,b) .Call( "overhead_cpp", a, b )
+overhead_c_symbol <- getNativeSymbolInfo( "overhead_c" )
+overhead_cpp_symbol <- getNativeSymbolInfo( "overhead_cpp" )
 
+overhead_c <- function(a,b) .Call( overhead_c_symbol, a, b )
+overhead_cpp <- function(a,b) .Call( overhead_cpp_symbol, a, b )
+
 ## load benchmarkin helper function
 suppressMessages(library(rbenchmark))
 
-benchmark(overhead_c(a,b),
-            overhead_cpp(a,b),
+benchmark(
+
+    overhead_cpp(a,b),
+    overhead_c(a,b),
+    
             columns=c("test", "replications", "elapsed", "relative", "user.self", "sys.self"),
                 order="relative",
                 replications=10000)

Modified: pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead_1.cpp
===================================================================
--- pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead_1.cpp	2010-09-23 15:20:20 UTC (rev 2146)
+++ pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead_1.cpp	2010-09-23 15:48:59 UTC (rev 2147)
@@ -3,9 +3,19 @@
 // This is a rewrite of the 'Writing R Extensions' section 5.10.1 example
 
 #include <Rcpp.h>
-using namespace Rcpp ;
+// using namespace Rcpp ;
 
-RcppExport SEXP overhead_cpp(SEXP a, SEXP b) {
+SEXP overhead_cpp(SEXP a, SEXP b) {
     return R_NilValue ;
 }
 
+extern "C" void R_init_overhead_1(DllInfo *info){
+
+     R_CallMethodDef callMethods[]  = {
+       {"overhead_cpp", (DL_FUNC) &overhead_cpp, 2},
+       {NULL, NULL, 0}
+     };
+
+     R_registerRoutines(info, NULL, callMethods, NULL, NULL);
+}
+

Modified: pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead_2.c
===================================================================
--- pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead_2.c	2010-09-23 15:20:20 UTC (rev 2146)
+++ pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead_2.c	2010-09-23 15:48:59 UTC (rev 2147)
@@ -3,8 +3,19 @@
 // This is a rewrite of the 'Writing R Extensions' section 5.10.1 example
 #include <R.h>
 #include <Rdefines.h>
+#include <R_ext/Rdynload.h>
 
 SEXP overhead_c(SEXP a, SEXP b) {
     return R_NilValue ;
 }
 
+void R_init_overhead_2(DllInfo *info){
+
+     R_CallMethodDef callMethods[]  = {
+       {"overhead_c", (DL_FUNC) &overhead_c, 2},
+       {NULL, NULL, 0}
+     };
+
+     R_registerRoutines(info, NULL, callMethods, NULL, NULL);
+}
+



More information about the Rcpp-commits mailing list