Visual C ++ function suddenly 170 ms slower (4 times more)

Over the past few months, I have been working on a Visual C ++ project to take pictures from cameras and process them. Until today, it took about 65 ms to update the data, but now it has increased dramatically. What happens: I run my program, and for the first 30 or so iterations, it runs as expected, and then the cycle time increases from 65 ms to 250 ms.

It is odd that after each function, I found out that the part of the code causing the slowdown is quite simple and has not been changed in a month. The data that enters it remains unchanged and identical for each iteration, but the execution time, which is initially less than 1 ms, suddenly increases to 170 ms, while the rest of the code still works as expected (in time).

Basically, I call the same function again and again, for the first 30 calls it makes, as it should, after that it slows down for no apparent reason. It may also be worth noting that this is a sudden change in runtime, not a gradual increase.

What could be the reason for this? The code skips some memory (~ 50 kbps), but not enough to guarantee a sudden 4x slowdown. If anyone has any ideas, I would love to hear them!

Edit: Wow, that was fast! Here's the code (minus some math) that slows down. I know that this is a function in which the computational time will increase rapidly if you increase the number of lines. The key here is that with the same data, it slows down after 30 iterations.

void CameraManager::IntersectLines()
{

    // Two custom classes
    TMaths maths;
    TLine line1, line2;

    while(lines.size()>0)
    {

        // Save the current line
        line1 = lines[0];

        // Then remove it from the list
        lines.erase(lines.begin());

        CvMat* aPoint;
        for (int i = 0; i<lines.size(); i++)
        {

            line2 = lines[i];

            aPoint = cvCreateMat(1, 4, CV_32FC1);

            // Calculate the point of intersection
            maths.Intersect(line1.xyz, line2.xyz, line1.uvw, line2.uvw, aPoint);

            // Add the point to the list
            points.push_back(aPoint);
            }

        }

    }

}

+3
source share
7 answers

Is it possible that after leaking a certain amount of memory, your computer should start paging material to / from? This will definitely slow down even simple functions.

, , , .

: , , . , , .

2: . -, ?

+9

( 50 /), Windows . , .

+5

, - . , . , . , . , , ..

+2

, - . , , , , , .

, , ...

[] , cvCreateMat ? - -?

+2

?

    // Then remove it from the list
    lines.erase(lines.begin());

( ) , . . . , . (. clear, ). clear , .

+1

, .

, , , ...

(In accordance with the current correct answer to this question: Profiling in Visual Studio 2008 PRO, you will need the Team Team VS 2008 version to use the built-in profiler, otherwise you will need an external profiler)

+1
source

You need to make your question more specific if you want useful answers.

0
source

Source: https://habr.com/ru/post/1750167/


All Articles