Skip to content

OpenCV 3.1's SVD is 3600 times slower than OpenCV 2.2's SVD #10084

@miyazakishogun

Description

@miyazakishogun
Detailed description

As it is already reported previously, SVD of version 2.3 and later is slower than SVD of version 2.2.
#4313
#7563
#7917

Below, I will report the benchmark result.

OpenCV 2.2 use LAPACK, so its SVD was fast, but OpenCV 2.3 use own implementation, and so its SVD is slow. OpenCV's SVD is implemented in lapack.cpp's JacobiSVDImpl_. I looked at this code, but I could not understand. I just guess that the speed of this function becomes slow when there are zero singular values. In order to check my hypothesis, two benchmark tests are done below: One with the matrix filled with the value "one," and the other with the matrix filled with random numbers.

System information (version)
  • OpenCV => 3.1 or 2.2
  • Operating System / Platform => Windows 64 Bit
  • Compiler => Visual Studio 2015
Steps to reproduce
const int ROW = 2000;
const int COL = 2000;
Mat mat = Mat::ones(ROW, COL, CV_64F);
int64 start = getTickCount();
cout << "start = " << start << endl;
SVD svd(mat);
int64 end = getTickCount();
cout << "end = " << end << endl;
int calctime = (int)((end - start) * 1000 / getTickFrequency());
cout << "duration = " << calctime << " [msec]" << endl << endl;
cout << "W = " << endl << svd.w.rowRange(Range(0, 9)) << endl;

For random matrix, following code is used for mat.

RNG gen(getTickCount());
Mat mat(ROW, COL, CV_64F);
gen.fill(mat, RNG::UNIFORM, 0.0, 1.0);
Benchmark result: random
Library Millisecond
MATLAB 3737
Python numpy 3878
C/C++ OpenCV 2.2 27523
Python OpenCV 3.3 147870
C/C++ OpenCV 3.1 187424
C/C++ NRC 3rd edit. 437539
C/C++ Eigen 940722
Benchmark result: ones
Library Millisecond
C/C++ Eigen 170
C/C++ OpenCV 2.2 2501
MATLAB 18784
Python numpy 21017
C/C++ NRC 3rd edit. 542057
Python OpenCV 3.3 9003935
C/C++ OpenCV 3.1 9004074

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions