Visual Studio slow down the execution when use conditional break points

后端 未结 1 1222
醉酒成梦
醉酒成梦 2021-02-20 09:50

Am using a For Loop like following:

 for (int i = 0; i < 1000; i++)
    {
        int mod = i % 1795;
       //Do some operations here
    }

1条回答
  •  情书的邮戳
    2021-02-20 10:28

    A conditional breakpoint is not something supported by the hardware; processors only support unconditional breakpoints. What's going on is that when you create a conditional breakpoint, the debugger inserts an unconditional breakpoint into your code. When the unconditional breakpoint is hit, the debugger evaluates your condition, and if it fails just resumes execution. Since each pass by the breakpoint location now requires stopping and involving the debugger, the code runs much more slowly.

    Depending on how often that code executes and how long your code takes to build it's often faster to just add an

    if (your condition)
    {
        System.Diagnostics.Debugger.Break();
    }
    

    or similar and just rebuild your app.

    0 讨论(0)
提交回复
热议问题