Timing the Execution of a Stored Procedure

  • What is the best method to time the execution of a stored procedure? I was thinking about printing or selecting the Current_TimeStamp at the beginning of the SP and at the end of the SP. We have SQL Server 2000 (SP3).

    Thanks in advance for you assistance, Kevin

  • Write at the beginning and at the end of store proc: print getdate().

  • If you just want duration and not actual CPU seconds used, then something like this works...

    --===== Declare a couple of variables to measure duration

    DECLARE @StartTime DATETIME

    DECLARE @EndTime   DATETIME

    --===== Start the duration "timer"

        SET @StartTime = GETDATE()

    --===== Run the code being tested

     yada-yada-yada

    --===== Stop the duration "timer

        SET @EndTime = GETDATE()

    --===== Finally, display the total duration of the test

         -- code in decimal seconds

     SELECT CONVERT(VARCHAR(20),@EndTime-@StartTime,114)

    ... will display the duration in the hh:mm:ss:mil format and is good up to 24 hours.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply