Today, I tested the performance of SVD function (because it is important for my work now) in OpenCV 2.3.1(http://sourceforge.net/projects/opencvlibrary/), Armadillo 2.4.4 (http://arma.sourceforge.net/download.html), Eigen 3.0.5(http://eigen.tuxfamily.org/) libraries and Matlab 2010b on my laptop, which runs a Windows 7 system. I used Visual Studio 2010 IDE for OpenCV, Armadillo and Eigen libraries (there are some details in configuration with them, it was time comsuming). In the test, I used a NxM matrix and called svd function in all the libraries and matlab’s svd function.

For the first test N=1000, M=1000, and the results were very suprised (due to the information from a same test on Linux: http://nghiaho.com/?p=954):

OpenCV took 12 secs, Armadillo took 12 secs, Eigen took 52 secs and Matlab: only 3 secs.

For the second test: N=10000, M = 1200, the results were: OpenCV took 140 secs, good bye Armadillo (I don’t know why), also say good bye to Eigen (Runtime error because the program could not allocate dynamically the big matrix), and Matlab took 6 secs. The third test with N=30000 and M=1200, Matlab took only 16 secs and OpenCV need 380 secs. I admired you, matlab. I also found some interesting things: Windows C++ program that used these libraries could not use multi core CPU like matlab (Why? Because VS IDE could not generate Windows programs that exploit multi cores architecture easily now – I am not sure). And the second thing I noted that matlab used much more memory (larger than 1GB in the case N=30000 and M=1200) than C++ programs. After this test, I come back to Matlab and I can conclude that: Matlab is the champion.

### Like this:

Like Loading...

*Related*

March 10, 2012 at 1:08 am

That’s very intereting results! Can you confirm the results from the SVD are similiar for the different libraries?

March 10, 2012 at 9:37 am

Yes man. I use the same matrix (values and dimensions) for all the tests. And I use the modified code from you page (thank you for that). I also notice that Armadillo and Eigen will fail because the program can not static allocate a very huge matrix (>10000×1000)-or may be I still not find the best way for doing that. I have tried dynamically locate a huge matrix with Armadillo but it still could not run. I’m trying to use multi core GotoBlas and Lapack librarries for a better result (maybe).

March 22, 2012 at 11:24 am

I tried the same thing you did in Matlab and got similar results, only because I asked it to return the singular values only eg. s = svd(M). But if I do the full SVD eg. [u s v] = svd(M) it is just as slow as the other libraies.

March 22, 2012 at 1:40 pm

No man. I just want to obtain eigen vectors and eigen values by using svd (in OpenCV, Armadillo, Eigen). I did not use the exact code as you did. In matlab, my code is very simple:

[eigVecs, eigVals, U]=svd(A,0);

I have modified Armadillo source code and use lapack+gotoblas and get very promising results: just 30 secs for 20000×1200 matrix, and 36 secs for 30000×1200 matrix. But it is far below matlab results. I also found that matlab use lapack and a multicore blas library for its svd function and that why it is the fastest.

March 24, 2012 at 2:29 pm

Just for fun I tried it on Octave 3.6.1, it only uses 1 core and got similiar results to you.

M = rand(1000,1000);

tic;[u,s,v]=svd(M,0);toc;

> Elapsed time is 13 seconds.

The Intel MKL libraries uses multicore, maybe worth a look at if you’re interested in the fastest SVD🙂

March 24, 2012 at 3:03 pm

But with 1000×1000, Armadillo and OpenCV are faster than Octave (only 12 secs), and after I modified the source code of Armadillo, it takes only 9 secs. In the same test, Matlab only takes 3 secs. I use lapack+openblas and got very impressive results: only 1.6 secs for 1000×1000 matrix and same results as matlab in other tests. I know Intel’s MKL is the best but it is not free+open source.

April 29, 2012 at 1:43 pm

[…] 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++ […]