SYSDATETIME()是否比GETDATE()成本高? [英] Does SYSDATETIME() cost more than GETDATE()?
问题描述
他们不要问cpu什么时候或者sysdatetime需要更多的指令来计算分数? Getdate是否正在四舍五入? sysdatetime可以更快,因为它不是四舍五入的工作?
如果我不存储纳秒,我显然不会使用sysdatetime,但是我在询问成本除了存储大小。 (我正在开发的当前应用程序运行sysdatetime()至少每秒280次)
它花了你写这个问题:
SELECT SYSDATETIME();
GO
DECLARE @d DATETIME2(7)= SYSDATETIME();
GO 10000
SELECT SYSDATETIME();
GO
DECLARE @d DATETIME = SYSDATETIME();
GO 10000
SELECT SYSDATETIME();
GO
DECLARE @d DATETIME2(7)= GETDATE();
GO 10000
SELECT SYSDATETIME();
GO
DECLARE @d DATETIME = GETDATE();
GO 10000
SELECT SYSDATETIME();
结果:
- 将SYSDATETIME分配给DATETIME:3.3 s
- 将GETDATE分配给DATETIME2(7): 3.4 s
- 将GETDATE分配给DATETIME:3.3 s
将SYSDATETIME分配给DATETIME2(7):3.4 s
所以看起来没关系。重要的是你分配给哪种类型的变量,甚至不是太多。 10000 / 0.1秒表示三角洲非常非常小,不足以担心。在这种情况下,我宁愿一致。
Is there any reason why I should stop using SYSDATETIME() everytime, instead of GETDATE() ?
Don't they both ask the cpu what time it is or does sysdatetime need more instructions to calculate the fractions? Does Getdate work on rounding it? Can sysdatetime be faster because it's not working on rounding?
I obviously wouldn't use sysdatetime if I'm not storing the nanoseconds, but I'm asking about the costs other than the storage size. (The current app I'm developing runs sysdatetime() at least 280 times a second)
This was quicker to test than it took you to write the question:
SELECT SYSDATETIME();
GO
DECLARE @d DATETIME2(7) = SYSDATETIME();
GO 10000
SELECT SYSDATETIME();
GO
DECLARE @d DATETIME = SYSDATETIME();
GO 10000
SELECT SYSDATETIME();
GO
DECLARE @d DATETIME2(7) = GETDATE();
GO 10000
SELECT SYSDATETIME();
GO
DECLARE @d DATETIME = GETDATE();
GO 10000
SELECT SYSDATETIME();
Results:
- Assigning SYSDATETIME to DATETIME2(7) : 3.4 s
- Assigning SYSDATETIME to DATETIME : 3.3 s
- Assigning GETDATE to DATETIME2(7) : 3.4 s
- Assigning GETDATE to DATETIME : 3.3 s
So it appears to not matter. What matters is what type of variable you assign it to, and even that is not by much. 10000/0.1 seconds means the delta is very, very small and not enough to worry about. I would rather be consistent in this case.
这篇关于SYSDATETIME()是否比GETDATE()成本高?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!