Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / VC9.0

Debugging technique

4.88/5 (7 votes)
27 Jan 2011CPOL 20.4K  
Timing code using debugger
We can use ‘Watch’ window to get time information. An undocumented pseudoregister, @CLK, can serve as a timer. In many cases, we just want a rough idea of the time between two points, and @CLK makes it easy to find out how long it took to execute between two breakpoints. Please note that this time includes the debugger overhead. The trick is to enter @CLK in watch window, running time between two breakpoints will be added up to the current clock value. You can reset the value by typing @CLK=0 in watch window.
The time is in microseconds, to get time in milliseconds, set the @CLK to @CLK/1000. Although it is not a perfect timer, @CLK is good enough for some general guesses.

Example:-
BEGIN_CODE <- Add break point here (B1)
{
    <<Code block>>
}
END_CODE <- Add another break point here (B2)


Debug the code using F5. Once you reach B1, type @CLK in watch window which will display current clock value. Now type @CLK=0 in watch window to reset the clock. Now press F5to continue, once the control reaches B2, watch window will show the time taken for executing code block between B1 and B2.
Note: This will not include the break time @B1.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)