Registered Member
|
Hello Forum,
I am a Python Numpy user in the past. Right now I would like to do the same numerical linear algebra calculation in C++ so I select Eigen. When I was doing some performance test with Eigen, I find some interesting thing regard to compilation of the source code. I am writing a simple sigmoid fuction in a eigentest.cpp source code:
I do the compilation using the simple command:
When I run the executable it returns an elapsed time of roughly 900ms. It is even slower than the Numpy. So I decide to do some research until I find this post on stackoverflow. http://stackoverflow.com/questions/24566920/eigen-matrix-vs-numpy-array-multiplication-performance Someone mentioned to add the compilation option like this:
Then I ran the program again. This time I got 170ms elapsed time. This is much faster than python Numpy. I would like to ask what did the -O2 and -DNDEBUG switch do in the compilation that boost the performance here? Do I need to apply this switch every time in my future compilation to get the best performance out of Eigen library? Thank you very much! |
Registered Member
|
It is a g++ related question, not an eigen one.
https://gcc.gnu.org/onlinedocs/gcc/Opti ... ze-Options ctrl+f for -o2 |
Registered Member
|
I think I should apply this optimization flag every time when compiling with g++. Then what about compile on Windows platform? According to the Configuring your project for optimal performance in this link: http://eigen.tuxfamily.org/index.php?title=Visual_Studio, I compiled the same code in visual studio 2010 professional using all the optimizer setting under Project property. This gave me an even worse result of 3500ms elapsed time. I will try osx compile when I have chance. Just a little bit confused on how to get best performance out of compiling on each platform. |
Moderator
|
Enabling compiler optimizations is indeed crucial in C++ to get rid of the deep function calls through inlining. -O2 is the minimal, -O3 is slightly better. This flag applies to both gcc and clang (default on OSX). For visual, the flag if /O2, or "release mode" through the interface.
|
Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient