• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

STL versus Armadillo versus Eigen in R using c++

Joined
4/8/11
Messages
131
Points
138
Here are time stats for running a max row function 100 times for each implementation using STL versus Armadillo versus Eigen on a matrix 50000 rows by 1000 columns containing random numbers between 0 and 3.

The R code.
C++:
library(Rcpp)
library(RcppArmadillo)
library(RcppEigen)
library(microbenchmark)
library(ggplot2)

Dummy <- matrix(runif(50000000,0,3), ncol = 1000)
sourceCpp("algorithm_matrix_STL.cpp")
sourceCpp("algorithm_matrix_Armadillo.cpp")
sourceCpp("algorithm_matrix_eigen.cpp")
tm <- microbenchmark::microbenchmark(MaxColSTL(Dummy), #Using STL algorithm max_element
                               MaxColArmadillo(Dummy), #Using RcppArmadillo
                               MaxColEigen(Dummy)) #Using RcppEigen

C++:
Unit: milliseconds
                   expr      min       lq     mean   median       uq       max neval
       MaxColSTL(Dummy) 411.0509 462.6502 523.6478 540.9864 559.2189  640.5903   100
MaxColArmadillo(Dummy) 241.8327 276.9529 374.6993 288.3489 301.6745 8648.5732   100
     MaxColEigen(Dummy) 345.9504 385.0690 405.8978 397.7753 422.4927  513.8324   100

On average the Armadillo is faster than the STL and Eigen implementations.

The cpp implementations are attached
 

Attachments

  • algorithm_matrix_Armadillo.cpp
    271 bytes · Views: 79
  • algorithm_matrix_eigen.cpp
    311 bytes · Views: 46
  • algorithm_matrix_STL.cpp
    608 bytes · Views: 54
Here is another example to test performance against; it is Boost uBLAS and STL algos. The code can be parallelised without race condition I feel since it is *loop parallel* pattern.
Am interested in your finding with regards to Eigen.
 

Attachments

  • TestMatrixMaxElements.cpp
    1.6 KB · Views: 77
Back
Top