Click here to Skip to main content
Click here to Skip to main content

Tagged as

Debugging technique

, 27 Jan 2011
Rate this:
Please Sign up or sign in to vote.
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)


About the Author

Web Developer
India India
No Biography provided

Comments and Discussions

GeneralReason for my vote of 5 Good trick! PinmemberStarfair31-Jan-11 3:30 
GeneralReason for my vote of 5 Very useful.. PinmemberPravin Patil, Mumbai30-Jan-11 21:26 
GeneralInnovation trick... Take my 5. PinmemberPravin Patil, Mumbai30-Jan-11 21:26 
GeneralReason for my vote of 5 Useful trick! PinmemberSauro Viti29-Jan-11 11:03 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140814.1 | Last Updated 27 Jan 2011
Article Copyright 2011 by Junaij
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid