开发者

Print Statement in SQL procedure should affect Performance?

I am using SQL Server procedures and I have a habit of using of Print statements in the stored procedures to differentiate the code of procedure.

I have almost 200-250 procedures in my DB. Should print statement affect the performance? I am working on multi-user Windows开发者_如何学JAVA application.


I found when running the below on my desktop that commenting out the print knocked about 15 seconds off the execution time meaning the average impact was 15µs in my simple test. RAISERROR WITH NOWAIT added an average of just over double that.

DECLARE @date DATETIME2

DECLARE 
  @count INT

SET @count = 1

SET @date = SYSUTCDATETIME()

WHILE @count < 1000000
BEGIN
--RAISERROR ('%d',0,1, @count) WITH NOWAIT
--PRINT @count
  SET @count = @count + 1
END

SELECT DATEDIFF(MICROSECOND, @date, SYSUTCDATETIME()) / 1000000. 


A handful of PRINT statements will have a negligible effect on performance - PRINTs in loops that are executed many thousands of times, however, may well cause performance issues.

It's unlikely that if you're experiencing performance problems with your queries that PRINT is the culprit - however, if in doubt, try some experiments!


Essentially there is an additional overhead introduced to the overall performance of your given process because you are asking SQL Server to pass output to the client, which you would not be doing otherwise (i.e. without the use of the PRINT statement).

Quantifying an additional overhead, in terms of will it have an impact on overall performance, will depend on just how much of an additional overhead you are applying.

So in other words, go and test it out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜