How to benchmark my t-sql directly using dmv dm_exec_sessions

Tested on Sql Azure 11.0.9206.32
/*Get actual reads, writes and other nice to know stuff for benchmarking.Notice go statements which are crucial since stats seem to update by batch.*/ 
go
if object_id('tempdb..#stats') is not null drop table #stats select getdate() as startTime,cpu_time,memory_usage,reads,writes,logical_reads,session_id into #stats from sys.dm_exec_sessions a where session_id=@@spid
go
--do your magic stuff that need tuning
go

select   datediff(ms,s2.startTime,getdate()) as ElapsedMs,   s1.cpu_time-s2.cpu_time as cpu_time,   s1.memory_usage-s2.memory_usage as memory_usage,   s1.reads-s2.reads as reads,   s1.writes-s2.writes as writes,   s1.logical_reads-s2.logical_reads as logical_reads from sys.dm_exec_sessions s1   join #stats s2   on s1.session_id=s2.session_Id   where s1.session_id=@@spid

Comments

Popular posts from this blog

Constructing nested array structs in BigQuery

How to decrypt stored password from SSMS registered servers

Cause for Parameter is incorrect 0x80070057 error in ssis