Today, I test big matrices (float) multiplication on my laptop (HP Elitebook 6930p – Duo 2 Core 2×2.4Ghz, 4Gb Ram, Windows 7 32 bit, VS 2010) with OpenCV 2.3.1, Armadillo 3.0.2, Eigen 3.0.5 and OpenBLAS 1.0, C/C++ simple matrices multiplication method and Matlab 2010b 32bit. The program is simple: A = matrix(dim1, dim2, float), B = matrix(dim2, dim3, float), C = A*B, ofcourse I did not include the initial time, just the time for calculation. And here are the results.

Matrices’ size | C | Armadillo | OpenCV | Eigen | C++ (use STL vector class) | OpenBLAS | Matlab |

1000×1000 | 1.45 | 0.125 | 1.76 | 0.87 | 1.47 | 0.062 | 0.062 |

2000×2000 | 11.64 | 0.94 | 14.2 | 6.93 | 11.23 | 0.99 | 0.54 |

3000×3000 | 38.11 | 3.28 | 47.2 | 23.51 | 37.99 | 1.75 | 1.7 |

4000×4000 | 90.84 | 7.33 | 110.37 | 53.7 | 90.2 | 7.91 | 4.2 |

5000×5000 | 180.74 | 15.65 | 213.4 | 104.11 | 181.02 | 10.8 | 7.3 |

6000×6000 | 315.46 | 27.32 | 376.46 | 186.1 | 316.3 | 25.33 | 12.74 |

It is clear that Matlab is the champion, like in SVD test, but I do not understand why OpenCV is the slowest, even slower than simple C and C++ implementation (C and C++ implementation have the same speed). OpenCV is two times slower than Eigen, Armadillo (in my test – I use OpenBLAS with Armadillo) have the same speed with OpenBLAS. I also notice that simple C/C++, OpenCV, Eigen use only one Core and Armadillo, OpenBLAS and Matlab use both 2 Cores of my machine.

May 3, 2012 at 7:45 am

Did you turn on optimisations in the compiler ? For template libraries this is critical.

Also, why are you still using a 32 bit operating system on a 64 bit machine?

May 3, 2012 at 10:35 am

I use VS 2010 and build with Release option. I do not known other optimize options for VS. I use 32 bit because my machine is 32 bit. I think the comparision is fair because all the libraries and Matlab is used default settings and on the same system (with the same matrices type). I known many people said that Windows is not reliable and slow, but that the reason we need better and faster programs. I supposed that Matlab is the fastest because it use Intel’s MKL library. I want to test ATLAS but I could not build it on my Windows system.

May 3, 2012 at 11:42 am

I guess you missed something about optimization as according to my experience there is no way to get 23.51 sec timing result for 3k x 3k matrix multiplication on eigen while matlab gives 1.7 sec because in some cases eigen gives better results than mkl. Could you share build configuration of eigen, opencv and armadillo.

May 3, 2012 at 12:50 pm

Sorry man. I used default setting for OpenCV 2.3.1 and Eigen 3.0.5 because I did not know how to configure them for better performance, could you show me how? I only set Armadillo to use BLAS and Lapack for the test.

January 4, 2015 at 10:48 am

” I also notice that simple C/C++, OpenCV, Eigen use only one Core and Armadillo, OpenBLAS and Matlab use both 2 Cores of my machine.” so result are obvious: 2 cores are faster then one core alone 🙂 ….