Visual studio 2019 slow debug build with for loop

Amadeo Kusch 1 Reputation point
2021-08-06T10:42:44.853+00:00

Hello
I was trying to debug a program with Visual Studio 2019 v142 with 10.0.19041.0 SDK, C++17 Standard
stepping through lines is ok but it's clearly slower at the execution of loops with many iterations such as this:

    ifstream in("text.txt");
    vector <string > words_to_find= {"apple", "monkey"};
    vector <pair<string, int>> matches;
    string line;
    while (getline(in, line))
    { 
        for (int g = 0; g < words_to_find.size(); g++)
        {
            int ret = line.find(words_to_find[g]); 
            if (ret  != string::npos)
            { 
                matches.push_back({words_to_find[g], (int)in.tellg()} );
            }
        }
    }

to complete the loop the debug version takes 14 seconds and the release version 2.5 seconds, and it's the same even if i just run the executables from a normal command line
any help?
thanks

Developer technologies Visual Studio Debugging
{count} votes

1 answer

Sort by: Most helpful
  1. RLWA32 49,536 Reputation points
    2021-08-06T11:35:35.557+00:00

    Why would you expect a debug build of an executable to run as quickly as a release build?

    In a debug build the compiler performs no optimizations; release builds contain optimized code. And, a debug build will include certain checks during execution that are not present in a release build.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.