Thursday 14 March 2019

High Precision Timing in SQL Server

Here's a simple snippet I wrote for high precision timing in SQL:

DECLARE @startTime datetime2;
DECLARE @endTime datetime2;

DECLARE @counter int = 0;
DECLARE @iterations int = 1000;

SET @startTime = SYSDATETIME();

WHILE @counter < @iterations
BEGIN
-- code to time here

SET @counter = @counter + 1;
END;

SET @endTime = SYSDATETIME();
SELECT DATEDIFF(MICROSECOND,@startTime,@endTime) / @iterations

No comments:

Post a Comment

How to reduce complexity and know everything.

Quality We have a great QA. His code is like a Rolex. You look at his gherkin, and smile.  It says what it's testing, in plain English, ...