Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Discrepancy in Performance between rotation() and linear() Functions in Eigen::Isometry3d

$
0
0

I'm optimizing my C++ code that uses Eigen. I've noticed that when using Eigen::Isometry3d, the rotation() function is much slower compared to linear(). To show this, I wrote a simple program to compute the multiplication between two rotation matrices:

Eigen::Transform< double, 3, Eigen::Isometry > a = Eigen::Isometry3d::Identity();Eigen::Transform< double, 3, Eigen::Isometry > b = Eigen::Isometry3d::Identity();for(int i=0; i<1000000; ++i){   auto d = a.rotation()*b.rotation();}  

I compiled it using g++ -O0 -o main main.cpp -I/usr/include/eigen3. I used -O0 to avoid optimizations that would remove the loop completely. When executed, it took approximately 15.351 seconds, as measured using the time command in Ubuntu.

However, when I replaced a.rotation() * b.rotation() with a.linear() * b.linear(), the execution time dramatically decreased to just 0.117 seconds.

According to the Eigen documentation, Isometry3d is an alias for Transform<float, 3, Eigen::Isometry>, and since the mode is set to Isometry, rotation() should essentially be an alias for linear(). This implies that using rotation() on an Isometry3d should be the same as using linear(). However, my tests show otherwise.

I also compiled the code with maximum optimization and inserted random values into the rotation matrix, but linear() still outperformed rotation() significantly.

I'm using Eigen version 3.3.4 and g++ version 11.4. Can anyone provide a reasonable explanation for this discrepancy?


Viewing all articles
Browse latest Browse all 12111

Trending Articles