Search code examples
c++performancematlabopencvcross-correlation

Is Matlab still slower than opencv in C++


According to this link and this one, it is said that opencv is much faster than matlab. First link is written in March 2012, second one is a bit later than that.

In the first link, it says, "Programs written in OpenCV run much faster than similar programs written in Matlab." and rates Matlab: 2/10 and OpenCV: 9/10

Consider, I have two float Matrix whose size are 1024*1024(mat1 and mat2). I want to correlate this matrices.

In matlab,

corr2(mat1,mat2);     //70-75 ms

In opencv, c++

Mat result(1,1,CV_32F);
matchTemplate(mat1,mat2,result, CV_TM_CCOEFF_NORMED);      // 145-150 ms

As far as I know, c and c++ are in approximately same speed.

So, I wonder, why matlab is faster than opencv/c++ while doing cross correlation. Is it because I am comparing wrong things (even though the results are same) or is the cross correlation implementation of matlab is double faster than opencv implementation?

Note that, I'm using Matlab 2013a and Visual Studio 2010.

Thanks,


Solution

  • Matlab built in functions comes with mkl and opencv's dont. So if two exactly equivalent functions are present in both, matlab is likely to be faster(much) than opencv. I have tried to do pseudo inverse on a large matrix and matlab beat everything(openblas,Armadillo,self integrated mkl etc) by at least 2 times. Then I just stopped figuring out why and just load the data into matlab and let it do the thing. opencv is by far the slowest. Try matrix multiplication on a 10000x10000 matrix in opencv. it took 10 minutes on my laptop. Matlab took 1 minute.