Click here to Skip to main content
15,669,910 members
Articles / Programming Languages / Visual C++ 9.0
Posted 27 Jan 2011

Tagged as


4 bookmarked

Debugging technique

Rate me:
Please Sign up or sign in to vote.
4.88/5 (7 votes)
27 Jan 2011CPOL
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.

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.


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

Written By
Web Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

GeneralReason for my vote of 5 Good trick! Pin
Starfair31-Jan-11 3:30
Starfair31-Jan-11 3:30 
GeneralReason for my vote of 5 Very useful.. Pin
Pravin Patil, Mumbai30-Jan-11 21:26
Pravin Patil, Mumbai30-Jan-11 21:26 
GeneralInnovation trick... Take my 5. Pin
Pravin Patil, Mumbai30-Jan-11 21:26
Pravin Patil, Mumbai30-Jan-11 21:26 
GeneralReason for my vote of 5 Useful trick! Pin
Sauro Viti29-Jan-11 11:03
professionalSauro Viti29-Jan-11 11:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.