question

AmadeoKusch-3381 avatar image
0 Votes"
AmadeoKusch-3381 asked AnnaXiu-MSFT commented

Visual studio 2019 slow debug build with for loop

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


vs-debugging
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @AmadeoKusch-3381, have you got any chance to check the reply from RLWA32?
Since the release mode is optimized for speed and performance, it will run faster than debug mode.

0 Votes 0 ·

1 Answer

RLWA32-6355 avatar image
0 Votes"
RLWA32-6355 answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.