How to check SQL Server Performance Tuning for Stored Procedures [closed] How to check SQL Server Performance Tuning for Stored Procedures [closed] sql-server sql-server

How to check SQL Server Performance Tuning for Stored Procedures [closed]


Personally, when I am testing the speed of a sproc I use something similar to the following:

DBCC FREEPROCCACHE;DBCC DROPCLEANBUFFERS;GOSET STATISTICS TIME ON;SET STATISTICS IO ON;GOEXEC <my sproc> [args]

DBCC FREEPROCCACHE

Use DBCC FREEPROCCACHE to clear the procedure cache. Freeing the procedure cache would cause, for example, an ad-hoc SQL statement to be recompiled rather than reused from the cache. If observing through SQL Profiler, one can watch the Cache Remove events occur as DBCC FREEPROCCACHE goes to work. DBCC FREEPROCCACHE will invalidate all stored procedure plans that the optimizer has cached in memory and force SQL Server to compile new plans the next time those procedures are run.

DBCC DROPCLEANBUFFERS

Use DBCC DROPCLEANBUFFERS to test queries with a cold buffer cache without shutting down and restarting the server. DBCC DROPCLEANBUFFERS serves to empty the data cache. Any data loaded into the buffer cache due to the prior execution of a query is removed.

Above shameless stolen from: this blog post

SET STATISTICS TIME ON

Displays the number of milliseconds required to parse, compile, and execute each statement.

Further Reading (MSDN)

SET STATISTICS IO ON

Causes SQL Server to display information regarding the amount of disk activity generated by Transact-SQL statements.

Further Reading (MSDN)

As for the accuracy of the query, that is something that you as the developer have to take a look at. I don't think there is an automated way to test the accuracy.

Hopefully that will get you started.

Note: I do this inside SSMS