Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Time a query or SP for comparisons

Author  Topic 

coolerbob
Aged Yak Warrior

841 Posts

Posted - 2005-03-31 : 07:32:31
I want to compare the performance of different queries.
Is there a way I can use SQL to get the time a query took to process?
How would you do this if you wanted to return how long a SP took in a OUTPUT parameter?

mr_mist
Grunnio

1870 Posts

Posted - 2005-03-31 : 07:34:24
Run your query in query analyzer

print getdate()
exec yourquery
print getdate()

You can loop that lots of times to get average, etc.

-------
Moo. :)
Go to Top of Page

coolerbob
Aged Yak Warrior

841 Posts

Posted - 2005-03-31 : 08:00:45
So simple!
Genious!
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-03-31 : 13:35:45
SET STATISTICS TIME ON

rockmoose
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2005-03-31 : 15:40:32
Be aware that simply running two queries which acess the same data can yield misleading results:

print getdate()
exec query1
print getdate()
exec query2
print getdate()

The first query will tend to load the necessary data into cache which makes the second query run quicker (since the data is already in cache).

You may want to look at flushing the data and/or procedure cache as a prelude to each query run.

HTH

=================================================================
In order to improve the mind, we ought less to learn than to contemplate.
-Rene Descartes, philosopher and mathematician (1596-1650)
Go to Top of Page
   

- Advertisement -