Vectorised unary functions - Eigen implementations?

Really interesting stuff here. I coded up some rough benchmarks comparing the performance of the log and exp functions.

Log showed some minor improvements in speed, but nothing particularly impressive:

log 
1000 randomly generated 10000 x 1 Vectors (milliseconds)
stan: 159
eigen: 148
1000 randomly generated 1000 x 1000 Matrices (milliseconds)
stan: 16508
eigen: 15180

Exp on the other hand showed a dramatic improvement:

exp
1000 randomly generated 10000 x 1 Vectors (milliseconds)
stan: 75
eigen: 22
1000 randomly generated 1000 x 1000 Matrices (milliseconds)
stan: 8644
eigen: 2395

I would guess that the difference in improvement is because Eigen’s exp supports AVX for doubles, whereas log only supports AVX for floats. Either way, interesting to see the performance boosts that are available.

Benchmarking code below, compiled with:

g++ -std=c++1y -march=native  -O3  -I . -I lib/eigen_3.3.3  eigen_log_exp_test.cpp

eigen_log_exp_test.cpp (3.9 KB)

(warning will use up approx 8gb RAM)

2 Likes