Visual Studio slow down the execution when use conditional break points

时间秒杀一切 提交于 2019-12-21 10:19:11

问题


Am using a For Loop like following:

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

it works fine, but when i put a break point and apply condition as mod=150 then it slow down the execution. why this is happening? what is actually happening when i add such conditional breakpoints?


回答1:


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.



来源:https://stackoverflow.com/questions/32391419/visual-studio-slow-down-the-execution-when-use-conditional-break-points

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!