欢迎投稿

今日深度:

SQLServer中,CPU主频对计算密集型SQL执行速度的影响,declare@co

SQLServer中,CPU主频对计算密集型SQL执行速度的影响,declare@co


从一个简单的SQL来看,CPU主频对计算密集型SQL执行速度影响的差别,测试语句有三个特点:简单SQL,计算密集型SQL,循环多次执行来放大执行时间

1,构造一个简单的插入语句SQL

2,通过随机排序,来模拟计算密集型操作

3,通过循环来放大执行时间

 

可以发现,100000次循环的情况下,在不同主频的CPU下,执行时间的差异还是比较大的。

declare @counter int = 0;
while @counter<100000
begin
	declare  @my_table table
	(
		c1 int,
		c2 varchar(100)
	);
	insert into @my_table 
	select top 1 c1,c2 from 
	(
		select 1 as c1,'a' as c2
		union all
		select 2 as c1,'b' as c2
		union all
		select 3 as c1,'c' as c2
		union all
		select 4 as c1,'d' as c2
		union all
		select 5 as c1,'e' as c2
		union all
		select 6 as c1,'f' as c2
		union all
		select 7 as c1,'g' as c2
		union all
		select 8 as c1,'g' as c2
		union all
		select 9 as c1,'i' as c2
		union all
		select 10 as c1,'j' as c2
	)t
	order by newid();

	set @counter = @counter + 1;
end

 

 

 

完全一样的SQL:

10年前的4代I7,老掉牙的CPU了,但是主频高,3.6GHz主频的CPU,2秒钟跑完

5年前的Xeon E5620,服务器CPU,但是主频低,2.4GHz,要6秒钟跑完

 

www.htsjk.Com true http://www.htsjk.com/Sql_Server/49217.html NewsArticle SQLServer中,CPU主频对计算密集型SQL执行速度的影响,declare@co 从一个简单的SQL来看,CPU主频对计算密集型SQL执行速度影响的差别,测试语句有三个特点:简单SQL,计算密集型SQL,循环多...
评论暂时关闭