Voyager-1 - The furthest spacecraft

Voyager-1 - The furthest spacecraft

Front Page


Performance Benchmark Rcpp

We perform some standard performance benchmarks of Rcpp code and compare these to standard algorithms in base R as well as custom packages.

Load standard packages, including Rcpp, ggplot2 and microbenchmark.

library(Rcpp)
getwd()
## [1] "/home/hduser/projects/rcode/tuftedemo/mosaic"
# source("~/projects/rcode/demo/rcpp/rcpp_sourceCpp_eg_funcs.R")
path_cpp = paste("/home/hduser/projects/rcode/demo/rcpp/")
# file6_eg_funcs = paste(my_paths$path_cpp, "cpp_library_functions_1.cpp", sep="" )
file6_eg_funcs = paste(path_cpp, "cpp_library_functions_1.cpp", sep="" )
sourceCpp(file6_eg_funcs)

Evaluate Rcpp code performance

x = c(1,2,3,4,5,6,7,10)
s1 = cumsum1(x)
cat("\n cumsum1 =    ", s1)
## 
##  cumsum1 =     1 3 6 10 15 21 28 38
s2 = cumsum2(x)
cat("\n cumsum2 =    ", s2)
## 
##  cumsum2 =     1 3 6 10 15 21 28 38
s3 = cumsum_sug(x)
cat("\n cumsum_sug = ", s3)
## 
##  cumsum_sug =  1 3 6 10 15 21 28 38
cat("\n finished \n")
## 
##  finished

from Yihui paper

#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
NumericVector timesTwo(NumericVector x) {
  return x * 2;
}

The above code should now be available in R, and the function timesTwo() available

vec = c(1,2,3,4)
timesTwo(vec)
## [1] 2 4 6 8

TODO - Rcpp versus standard algorithms

TODO - Rcpp versus contributed packages

TODO - Microbenchmarks

TODO

References

Yihui on program engines Yihui bookdown

A linked phrase.

And what does that link phrase id actually do in this context?


RB References Voyager-1

 

A work by Alan Holtz

Alan.holtz.data@gmail.com