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

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


Author: romain
Date: 2010-09-23 17:20:20 +0200 (Thu, 23 Sep 2010)
New Revision: 2146

Added:
   pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead.r
   pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead.sh
   pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead_1.cpp
   pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead_2.c
Modified:
   pkg/Rcpp/inst/examples/ConvolveBenchmarks/buildAndRun.sh
Log:
trying to quantify C and C++ overhead

Modified: pkg/Rcpp/inst/examples/ConvolveBenchmarks/buildAndRun.sh
===================================================================
--- pkg/Rcpp/inst/examples/ConvolveBenchmarks/buildAndRun.sh	2010-09-23 14:37:05 UTC (rev 2145)
+++ pkg/Rcpp/inst/examples/ConvolveBenchmarks/buildAndRun.sh	2010-09-23 15:20:20 UTC (rev 2146)
@@ -16,4 +16,5 @@
 R CMD SHLIB convolve5_cpp.cpp
 
 # call R so that we get an interactive session
-Rscript exampleRCode.r 
+Rscript exampleRCode.r
+

Added: pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead.r
===================================================================
--- pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead.r	                        (rev 0)
+++ pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead.r	2010-09-23 15:20:20 UTC (rev 2146)
@@ -0,0 +1,22 @@
+#!/usr/bin/r
+
+set.seed(42)
+a <- rnorm(100)
+b <- rnorm(100)
+
+## load shared libraries with wrapper code
+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 )
+
+## load benchmarkin helper function
+suppressMessages(library(rbenchmark))
+
+benchmark(overhead_c(a,b),
+            overhead_cpp(a,b),
+            columns=c("test", "replications", "elapsed", "relative", "user.self", "sys.self"),
+                order="relative",
+                replications=10000)
+

Added: pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead.sh
===================================================================
--- pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead.sh	                        (rev 0)
+++ pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead.sh	2010-09-23 15:20:20 UTC (rev 2146)
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+rm -f *.o *.so
+
+# build the shared library for the C variant
+R CMD SHLIB overhead_2.c
+
+# build the shared library for the C++ variant
+# we have to let R know where the Rcpp header and library are
+export PKG_CPPFLAGS=`Rscript -e "Rcpp:::CxxFlags()"`
+export PKG_LIBS=`Rscript -e "Rcpp:::LdFlags()"`
+R CMD SHLIB overhead_1.cpp
+
+# call R so that we get an interactive session
+Rscript overhead.r
+

Added: pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead_1.cpp
===================================================================
--- pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead_1.cpp	                        (rev 0)
+++ pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead_1.cpp	2010-09-23 15:20:20 UTC (rev 2146)
@@ -0,0 +1,11 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+
+// This is a rewrite of the 'Writing R Extensions' section 5.10.1 example
+
+#include <Rcpp.h>
+using namespace Rcpp ;
+
+RcppExport SEXP overhead_cpp(SEXP a, SEXP b) {
+    return R_NilValue ;
+}
+

Added: pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead_2.c
===================================================================
--- pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead_2.c	                        (rev 0)
+++ pkg/Rcpp/inst/examples/ConvolveBenchmarks/overhead_2.c	2010-09-23 15:20:20 UTC (rev 2146)
@@ -0,0 +1,10 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+
+// This is a rewrite of the 'Writing R Extensions' section 5.10.1 example
+#include <R.h>
+#include <Rdefines.h>
+
+SEXP overhead_c(SEXP a, SEXP b) {
+    return R_NilValue ;
+}
+



More information about the Rcpp-commits mailing list