title: Eigen copy constructor vs. operator= performance
body: <p>
  At my job, I use the Eigen math library. I have encountered a behavior where using an Eigen Matrix copy constructor in an initializer list for my own classes is significantly slower than using <code>operator=</code> in the constructor body.</p>
  
  <p>
  In these examples, "Matrix" is a statically-sized dense matrix.</p>
  
  <pre><code>class Slow {
      public:
          Slow(const Matrix &amp;m) : my_matrix{m} {}
      private:
          Matrix my_matrix;
  }
  
  class Fast {
      public:
          Fast(const Matrix &amp;m) : my_matrix{} {
              my_matrix = m;
          }
      private:
          Matrix my_matrix;
  }
  </code></pre>
  
  <p>
  My program frequently invokes the copy constructor of my class, and the difference in performance between the two options above is quite noticeable. I verified that the generated assembly is in fact different.</p>
  
  <p>I understand that the copy-constructor and operator= are not the same, but I am having trouble wading through the Eigen source code to figure out why one is faster than the other. Can anyone with some Eigen expertise weigh in on what happens under the hood that causes operator= to be so much faster? Insight and/or links to recommended reading are equally welcome.</p>