Skip to content

Commit 2fc3a3a

Browse files
committed
Improve description and some code formating
1 parent d922909 commit 2fc3a3a

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

Stored_Procedure/sp_BenchmarkTSQL.sql

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
IF OBJECT_ID('dbo.sp_BenchmarkTSQL', 'P') IS NULL
1+
IF OBJECT_ID('dbo.sp_BenchmarkTSQL', 'P') IS NULL
22
EXECUTE ('CREATE PROCEDURE dbo.sp_BenchmarkTSQL AS SELECT 1;');
33
GO
44

55

66
ALTER PROCEDURE dbo.sp_BenchmarkTSQL(
7-
@tsqlStatement NVARCHAR(MAX)
8-
, @numberOfExecution INT = 10
9-
, @saveResults BIT = 0
10-
, @clearCache BIT = 0
11-
, @calcMedian BIT = 0
12-
, @printStepInfo BIT = 1
13-
, @durationAccuracy VARCHAR(10) = 'ns'
7+
@tsqlStatement NVARCHAR(MAX)
8+
, @numberOfExecution INT = 10
9+
, @saveResults BIT = 0
10+
, @clearCache BIT = 0
11+
, @calcMedian BIT = 0
12+
, @printStepInfo BIT = 1
13+
, @durationAccuracy VARCHAR(3) = 'ns'
1414
)
1515
/*
1616
.SYNOPSIS
17-
Calculate SQL statement execution time, save results if need.
17+
Calculate TSQL statement execution time, save results if needed.
1818
1919
.DESCRIPTION
20-
Run SQL statement specified times, show results in ms, insert execution details into table dbo.BenchmarkTSQL (create if not exist).
20+
Run SQL statement specified times, show results, insert execution details into table dbo.BenchmarkTSQL (create if not exist).
2121
2222
.PARAMETER @tsqlStatement
2323
TSQL statement for benchmarking.
@@ -26,7 +26,7 @@ ALTER PROCEDURE dbo.sp_BenchmarkTSQL(
2626
Number of execution TSQL statement.
2727
2828
.PARAMETER @saveResults
29-
Save benchmark details to dbo.BenchmarkTSQL table.
29+
Save benchmark details to dbo.BenchmarkTSQL table if @saveResults = 1.
3030
3131
.PARAMETER @clearCache
3232
Clear cached plan for TSQL statement.
@@ -35,7 +35,10 @@ ALTER PROCEDURE dbo.sp_BenchmarkTSQL(
3535
Calculate pseudo median of execution time.
3636
3737
.PARAMETER @printStepInfo
38-
PRINT detailed step information: step count, start time, end time, duration
38+
PRINT detailed step information: step count, start time, end time, duration.
39+
40+
.PARAMETER @durationAccuracy
41+
Duration accuracy calculation, possible values: ns, mcs, ms, ss, s, mi, n, hh, wk, ww, dd, d.
3942
4043
.EXAMPLE
4144
EXEC sp_BenchmarkTSQL @tsqlStatement = 'SELECT * FROM , sys.databases';
@@ -50,7 +53,7 @@ ALTER PROCEDURE dbo.sp_BenchmarkTSQL(
5053
, @saveResults = 1
5154
, @calcMedian = 1
5255
, @clearCache = 1
53-
, @printStepInfo = 0
56+
, @printStepInfo = 1
5457
, @durationAccuracy = 'ms';
5558
5659
.LICENSE MIT
@@ -78,6 +81,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
7881
Author: Konstantin Taranov
7982
Modified date: 2018-01-01
8083
Version: 2.2
84+
85+
Author: Konstantin Taranov
86+
Modified date: 2018-01-04
87+
Version: 2.3
8188
*/
8289
AS
8390
BEGIN TRY
@@ -103,7 +110,7 @@ BEGIN TRY
103110
, 'dd' -- day
104111
, 'd' -- day
105112
)
106-
THROW 55003, '@durationAccuracy can be only in this values: ns, mcs, ms, ss, s, mi, n, hh. See DATEDIFF https://docs.microsoft.com/en-us/sql/t-sql/functions/datediff-transact-sql' , 1;
113+
THROW 55003, '@durationAccuracy can be only in this values: ns, mcs, ms, ss, s, mi, n, hh, wk, ww, dd, d. See DATEDIFF https://docs.microsoft.com/en-us/sql/t-sql/functions/datediff-transact-sql' , 1;
107114

108115
IF EXISTS (
109116
SELECT 1
@@ -148,7 +155,7 @@ BEGIN TRY
148155
, ClearCache BIT
149156
, PrintStepInfo BIT
150157
, DurationAccuracy VARCHAR(10)
151-
);
158+
);
152159

153160
SET @startTime = CONVERT(VARCHAR(27), CAST(CURRENT_TIMESTAMP AS DATETIME2(7)), 121);
154161
PRINT('Benchmark started at ' + @startTime + ' by ' + @originalLogin);
@@ -163,7 +170,7 @@ BEGIN TRY
163170
SELECT @plan_handle = plan_handle
164171
FROM sys.dm_exec_cached_plans
165172
CROSS APPLY sys.dm_exec_sql_text(plan_handle)
166-
WHERE [text] LIKE @tsqlStatement; -- LIKE instead = (equal) because = ignoring trailing spaces
173+
WHERE [text] LIKE @tsqlStatement; -- LIKE instead = (equal) because = ignore trailing spaces
167174

168175
IF @plan_handle IS NOT NULL DBCC FREEPROCCACHE (@plan_handle);
169176
END;
@@ -344,7 +351,7 @@ BEGIN TRY
344351
, @originalLogin
345352
FROM @t;
346353

347-
SET NOCOUNT ON;
354+
SET NOCOUNT OFF;
348355
END TRY
349356

350357
BEGIN CATCH

0 commit comments

Comments
 (0)