有没有比使用分析器更简单的方法来测量MS-SQL中的SQL性能?
我一直在使用我在互联网上找到的这个脚本,它给了我测量,但我不知道它有多准确.
DECLARE @StartTime datetime;
DBCC DROPCLEANBUFFERS -- Force data/index pages out of buffer cache for valid test
SET @StartTime = GETDATE() -- Measurement Starts
-->Insert SQL CALL/Script here
-- Measurement Ends
SELECT ExecutionTimeInMS = DATEDIFF(millisecond, @StartTime, getdate())
GO
是否有类似的替代方案可以在我正在做出的选择上获得快速,肮脏,通常准确的脉冲?
它已经返回了一些令人惊讶的结果,但我不知道在测试查询或测试工具/脚本中引发意外的情况?
最佳答案 这是我的测试设置:
DBCC DROPCLEANBUFFERS
DBCC freeproccache
SET STATISTICS IO ON
SET STATISTICS TIME ON
SELECT * FROM sys.all_columns
这给你很好的输出(在消息选项卡上):
(4307 row(s) affected)
Table 'syscolrdb'. Scan count 1, logical reads 167, physical reads 0, read-ahead reads 167, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'syscolpars'. Scan count 1, logical reads 12, physical reads 1, read-ahead reads 10, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
SQL Server Execution Times:
CPU time = 78 ms, elapsed time = 738 ms.