I'm trying to figure out why a SQL Server stored procedure is executing slowly, so I've put in some crude timers, like this:
Create Procedure DoStuff
As Begin
Declare @Stopwatch datetime
Set @Stopwatch=GetDate()
Print char(13) + 'Task A'
/* Perform Task A */
Print DateDiff(ms, @Stopwatch, GetDate()); Set @Stopwatch = GetDate()
Print char(13) + 'Task B'
/* Perform Task B */
Print DateDiff(ms, @Stopwatch, GetDate()); Set @Stopwatch = GetDate()
Print char(13) + 'Task C'
-- Perform Task C
Print DateDiff(ms, @Stopwatch, GetDate()); Set @Stopwatch = GetDate()
End
Exec DoStuff
I'm getting something like this:
Task A 0 Task B 80 Task C 100
So I would think the procedure would take 180 ms to execute. However, the procedure takes 3000+ ms to execute; in Client Statistics, I get
Client processing time: 12 Total execution time: 3105 Wait time on server replies: 3093
What accounts for the extra ~2800 ms?