Registered Member
|
Hi All,
I apologize if this question has been asked and answered, but I have been looking for some time and have found no suitable conclusion. So I had some code using Eigen that seemed to be running oddly slowly. I was able to confine the issue to what seems to be setting elements of a vector in a coefficient wise fashion. Here is the code of the test: Just writing to doubles:
Writing to an Eigen vector:
Now the latter snippet runs incomparably slowly with respect to the first and this just does not seem like it should be the case. Is there anything that I can do to get around this? Thanks all. |
Moderator
|
Make sure you compiled with optimization enabled (-O2)
|
Registered Member
|
Thanks for the idea, but I already am using -O2 (actually -O3, but I just tried -O2 to no avail.)
|
Moderator
|
which compiler version? also remark that your small benchmark could easily be too aggressively optimized by the compiler which could totally removes the loops... The best is to check the generated assembly in your real code, e.g., enclose your relevant part with:
EIGEN_ASM_COMMENT("my begin") EIGEN_ASM_COMMENT("my end") compile the file with -S -O2 -DNDEBUG and search for "my begin" in the generated ASM file... If you see "call" instructions that means some functions have not been properly inlined... |
Registered Member
|
Thank you very much. Indeed the compiler was optimizing away the loop in the first example. I definitely feel dumb.
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]