So I’m thinking of using the Eigen matrix library for a project I’m doing (2D space simulator). I just went ahead and profiled some code with Eigen::Vector2d, and with bare arrays. I noticed a 10x improvement in assigning values to elements in the array, and a 40x improvement in calculating the dot products.
Here is my profiling if you want to check it out, basically it’s ~4.065s against ~0.110s.
Obviously bare arrays are much more efficient at dot products and assigning stuff. So why use the Eigen library (or any other library, Eigen just seemed the fastest)? Is it stability? Complicated maths that would be hard to code by yourself efficiently?
The real win for these libraies is the built in SIMD vectorization.
It looks like eigen doesn’t enable that by default and you need to enable it with a define / compiler switch. (EDIT: Misread the link, it’s enabled if it detects that the compiler supports it, and you need to enable the instructions on some compilers, still, may or may not be on by default on your compiler)
(Not to mention the fact that they are typically more thoroughly tested than a home rolled solution, and enable all sorts of complicated/interesting stuff that’s a real bear to code by hand)