使用条件断点时,Visual Studio的减慢执行 [英] Visual Studio slow down the execution when use conditional break points
问题描述
我使用for循环类似以下内容:
Am using a For Loop like following:
for (int i = 0; i < 1000; i++)
{
int mod = i % 1795;
//Do some operations here
}
它工作正常,但是当我把一个破发点,并应用条件的模= 150
则减慢执行。为什么会这样?什么是实际发生的事情,当我添加这样的条件断点?
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?
推荐答案
一个条件断点没有硬件支持的东西;处理器仅支持无条件断点。这是怎么回事是,当你创建一个条件断点,调试器插入一个无条件断点到你的代码。当无条件断点时,调试器评估您的情况,如果失败只是恢复执行。由于每个路过的断点位置,现在需要停止并涉及调试器,代码运行速度要慢得多。
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.
这篇关于使用条件断点时,Visual Studio的减慢执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!