Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio slow down the execution when use conditional break points

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?

enter image description here

like image 754
sujith karivelil Avatar asked Sep 04 '15 06:09

sujith karivelil


1 Answers

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.

like image 196
Billy ONeal Avatar answered Oct 08 '22 12:10

Billy ONeal