title: Eigen Matrix vs Numpy Array multiplication performance
body: <p>I read <a href="https://stackoverflow.com/questions/10366054/c-performance-in-eigen-librar">in this question</a> that <code>eigen</code> has very good performance. However, I tried to compare <code>eigen</code> <code>MatrixXi</code> multiplication speed vs <code>numpy</code> <code>array</code> multiplication. And <code>numpy</code> performs better (~26 seconds vs. ~29). Is there a more efficient way to do this <code>eigen</code>?</p>
  
  <p>Here is my code:</p>
  
  <p>Numpy:</p>
  
  <pre><code>import numpy as np
  import time
  
  n_a_rows = 4000
  n_a_cols = 3000
  n_b_rows = n_a_cols
  n_b_cols = 200
  
  a = np.arange(n_a_rows * n_a_cols).reshape(n_a_rows, n_a_cols)
  b = np.arange(n_b_rows * n_b_cols).reshape(n_b_rows, n_b_cols)
  
  start = time.time()
  d = np.dot(a, b)
  end = time.time()
  
  print "time taken : {}".format(end - start)
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>time taken : 25.9291000366
  </code></pre>
  
  <p>Eigen:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;Eigen/Dense&gt;
  using namespace Eigen;
  int main()
  {
  
    int n_a_rows = 4000;
    int n_a_cols = 3000;
    int n_b_rows = n_a_cols;
    int n_b_cols = 200;
  
    MatrixXi a(n_a_rows, n_a_cols);
  
    for (int i = 0; i &lt; n_a_rows; ++ i)
        for (int j = 0; j &lt; n_a_cols; ++ j)
          a (i, j) = n_a_cols * i + j;
  
    MatrixXi b (n_b_rows, n_b_cols);
    for (int i = 0; i &lt; n_b_rows; ++ i)
        for (int j = 0; j &lt; n_b_cols; ++ j)
          b (i, j) = n_b_cols * i + j;
  
    MatrixXi d (n_a_rows, n_b_cols);
  
    clock_t begin = clock();
  
    d = a * b;
  
    clock_t end = clock();
    double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
    std::cout &lt;&lt; "Time taken : " &lt;&lt; elapsed_secs &lt;&lt; std::endl;
  
  }
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>Time taken : 29.05
  </code></pre>
  
  <p>I am using <code>numpy 1.8.1</code> and <code>eigen 3.2.0-4</code>.</p>