Timing T-SQL

So my client asked me to remove all the stored procedure and temp table calls from my code to move toward just using functions (which I wanted to use in the first place but they hadn’t give me “create function” rights).

After converting my code to use just functions, it made me wonder which was faster, and I didn’t want to pull out SQL Profiler … I wondered if I could do it in SQL Management Studio directly writing some T-SQL and I came across this website:

http://sqlserver2000.databases.aspfaq.com/how-do-i-time-my-t-sql-code.html

That was nice and simple … exactly what I needed

DECLARE @a DATETIME, @b DATETIME
SET @a = CURRENT_TIMESTAMP

{MY CODE}

SET @b = CURRENT_TIMESTAMP
SELECT DATEDIFF(MS, @a, @b)

It just so happened that most of the time the stored procedure route was actually faster … but added additional querying steps and unnecessary added tables that they didn’t want to do.  And they thought it looked messier … the client is always right (so they say) … so functions it is.

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: