如何用程序做地理性能测试
How to do geography performance test with procedures
我想测试我的程序在有和没有索引的情况下的性能,并比较经过的时间和 cpu 时间。我的程序如下所示:
create procedure p_search_vehicle
@IdCustomer int,
@idGroupVehicle int = null,
@ResultCount int= null,
@Radiant int= null
as
begin
if @IdCustomer is null
begin
print 'The argument cannot be null'
return
end
declare @start geography
set @start = (select location from Customer where idCustomer = @idCustomer)
--- @Result null group null radiant null
if @ResultCount is null and @idGroupVehicle is null and @Radiant is null
select top 10
idVehicle, idGroupVehicle, brand, model, maxRange, weight, maxSpeed, nameLocation, @start.STDistance(locationVehicle)/1000 as distanceInKm
from
Vehicle
where
(@start.STDistance(locationVehicle)/1000 is not null)
order by
@start.STDistance(locationVehicle)/1000 asc
---@Result null radiant null
else if @ResultCount is null and @Radiant is null
select top 10
idVehicle, idGroupVehicle, brand, model, maxRange, weight, maxSpeed, nameLocation, @start.STDistance(locationVehicle)/1000 as distanceInKm
from
Vehicle
where
idGroupVehicle = @idGroupVehicle
and (@start.STDistance(locationVehicle)/1000 is not null)
order by
@start.STDistance(locationVehicle)/1000 asc
---@Result null
else if @Radiant is null
select top(@ResultCount) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where idGroupVehicle= @idGroupVehicle and (@start.STDistance(locationVehicle)/1000 is not null)
order by @start.STDistance(locationVehicle)/1000 asc
---@@idGroupVehicle null @Radiant is null
else if @idGroupVehicle is null and @Radiant is null
select TOP(@ResultCount) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where (@start.STDistance(locationVehicle)/1000 is not null)
order by @start.STDistance(locationVehicle)/1000 asc
---@idGroupVehicle is null and @ResultCount is null
else if @idGroupVehicle is null and @ResultCount is null
select top 10 idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where (@start.STDistance(locationVehicle)/1000 <= @Radiant)
order by @start.STDistance(locationVehicle)/1000 asc
--- @idGroupVehicle is null
else if @idGroupVehicle is null
select TOP(@ResultCount) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where (@start.STDistance(locationVehicle)/1000 <= @Radiant)
order by @start.STDistance(locationVehicle)/1000 asc
--- all options
else
select TOP(@ResultCount) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where idGroupVehicle= @idGroupVehicle and (@start.STDistance(locationVehicle)/1000 <= @Radiant)
order by @start.STDistance(locationVehicle)/1000 asc
end
go
我已经使用 SET STATISTICS IO, TIME ON 测试了这个过程
DBCC FREEPROCCACHE;
DBCC DROPCLEANBUFFERS;
检查点
去吧,但我必须改变一些东西才能进行测试,永久设置所有参数并丢弃创建过程并声明每个参数
SET STATISTICS IO, TIME ON
DBCC FREEPROCCACHE;
DBCC DROPCLEANBUFFERS;
CHECKPOINT
GO
declare @IdCustomer int = 1,
@idGroupVehicle int = null,
@ResultCount int= null,
@Radiant int= null
begin
if @IdCustomer is null
begin
print 'The argument cannot be null'
return
end
declare @start geography
SET @start = (select location from Customer where idCustomer=@idCustomer )
---@Result null group null radiant null
if @ResultCount is null and @idGroupVehicle is null and @Radiant is null
begin
select top 10 idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where (@start.STDistance(locationVehicle)/1000 is not null)
order by @start.STDistance(locationVehicle)/1000 asc
end
---@Result null radiant null
if @ResultCount is null and @Radiant is null
begin
select top 10 idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where idGroupVehicle= 1 and (@start.STDistance(locationVehicle)/1000 is not null)
order by @start.STDistance(locationVehicle)/1000 asc
end
---@Result null
if @Radiant is null
begin
select TOP(5) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where idGroupVehicle= 1 and (@start.STDistance(locationVehicle)/1000 is not null)
order by @start.STDistance(locationVehicle)/1000 asc
end
---@@idGroupVehicle null @Radiant is null
if @idGroupVehicle is null and @Radiant is null
begin
select TOP(5) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where (@start.STDistance(locationVehicle)/1000 is not null)
order by @start.STDistance(locationVehicle)/1000 asc
end
---@idGroupVehicle is null and @ResultCount is null
if @idGroupVehicle is null and @ResultCount is null
begin
select top 10 idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where (@start.STDistance(locationVehicle)/1000 <= 1)
order by @start.STDistance(locationVehicle)/1000 asc
end
--- @idGroupVehicle is null
if @idGroupVehicle is null
begin
select TOP(5) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where (@start.STDistance(locationVehicle)/1000 <= 1)
order by @start.STDistance(locationVehicle)/1000 asc
end
--- all options
else
begin
select TOP(5) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where idGroupVehicle= 1 and (@start.STDistance(locationVehicle)/1000 <= 1)
order by @start.STDistance(locationVehicle)/1000 asc
end
end
是否可以通过其他方式测试过程以显示执行时间和受影响的行,而不对过程进行任何更改?
您不必将您的程序转换为测试脚本。而只是 调用 它。并且不要使用冷过程或页面缓存进行测试。这是一个非常不寻常的状态。
SET STATISTICS IO, TIME ON
GO
declare @IdCustomer int = 1,
@idGroupVehicle int = null,
@ResultCount int= null,
@Radiant int= null
exec p_search_vehicle @IdCustomer, @idGroupVehicle, @ResultCount, @Radiant
GO
SET STATISTICS IO, TIME OFF
我想测试我的程序在有和没有索引的情况下的性能,并比较经过的时间和 cpu 时间。我的程序如下所示:
create procedure p_search_vehicle
@IdCustomer int,
@idGroupVehicle int = null,
@ResultCount int= null,
@Radiant int= null
as
begin
if @IdCustomer is null
begin
print 'The argument cannot be null'
return
end
declare @start geography
set @start = (select location from Customer where idCustomer = @idCustomer)
--- @Result null group null radiant null
if @ResultCount is null and @idGroupVehicle is null and @Radiant is null
select top 10
idVehicle, idGroupVehicle, brand, model, maxRange, weight, maxSpeed, nameLocation, @start.STDistance(locationVehicle)/1000 as distanceInKm
from
Vehicle
where
(@start.STDistance(locationVehicle)/1000 is not null)
order by
@start.STDistance(locationVehicle)/1000 asc
---@Result null radiant null
else if @ResultCount is null and @Radiant is null
select top 10
idVehicle, idGroupVehicle, brand, model, maxRange, weight, maxSpeed, nameLocation, @start.STDistance(locationVehicle)/1000 as distanceInKm
from
Vehicle
where
idGroupVehicle = @idGroupVehicle
and (@start.STDistance(locationVehicle)/1000 is not null)
order by
@start.STDistance(locationVehicle)/1000 asc
---@Result null
else if @Radiant is null
select top(@ResultCount) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where idGroupVehicle= @idGroupVehicle and (@start.STDistance(locationVehicle)/1000 is not null)
order by @start.STDistance(locationVehicle)/1000 asc
---@@idGroupVehicle null @Radiant is null
else if @idGroupVehicle is null and @Radiant is null
select TOP(@ResultCount) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where (@start.STDistance(locationVehicle)/1000 is not null)
order by @start.STDistance(locationVehicle)/1000 asc
---@idGroupVehicle is null and @ResultCount is null
else if @idGroupVehicle is null and @ResultCount is null
select top 10 idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where (@start.STDistance(locationVehicle)/1000 <= @Radiant)
order by @start.STDistance(locationVehicle)/1000 asc
--- @idGroupVehicle is null
else if @idGroupVehicle is null
select TOP(@ResultCount) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where (@start.STDistance(locationVehicle)/1000 <= @Radiant)
order by @start.STDistance(locationVehicle)/1000 asc
--- all options
else
select TOP(@ResultCount) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where idGroupVehicle= @idGroupVehicle and (@start.STDistance(locationVehicle)/1000 <= @Radiant)
order by @start.STDistance(locationVehicle)/1000 asc
end
go
我已经使用 SET STATISTICS IO, TIME ON 测试了这个过程 DBCC FREEPROCCACHE; DBCC DROPCLEANBUFFERS; 检查点 去吧,但我必须改变一些东西才能进行测试,永久设置所有参数并丢弃创建过程并声明每个参数
SET STATISTICS IO, TIME ON
DBCC FREEPROCCACHE;
DBCC DROPCLEANBUFFERS;
CHECKPOINT
GO
declare @IdCustomer int = 1,
@idGroupVehicle int = null,
@ResultCount int= null,
@Radiant int= null
begin
if @IdCustomer is null
begin
print 'The argument cannot be null'
return
end
declare @start geography
SET @start = (select location from Customer where idCustomer=@idCustomer )
---@Result null group null radiant null
if @ResultCount is null and @idGroupVehicle is null and @Radiant is null
begin
select top 10 idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where (@start.STDistance(locationVehicle)/1000 is not null)
order by @start.STDistance(locationVehicle)/1000 asc
end
---@Result null radiant null
if @ResultCount is null and @Radiant is null
begin
select top 10 idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where idGroupVehicle= 1 and (@start.STDistance(locationVehicle)/1000 is not null)
order by @start.STDistance(locationVehicle)/1000 asc
end
---@Result null
if @Radiant is null
begin
select TOP(5) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where idGroupVehicle= 1 and (@start.STDistance(locationVehicle)/1000 is not null)
order by @start.STDistance(locationVehicle)/1000 asc
end
---@@idGroupVehicle null @Radiant is null
if @idGroupVehicle is null and @Radiant is null
begin
select TOP(5) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where (@start.STDistance(locationVehicle)/1000 is not null)
order by @start.STDistance(locationVehicle)/1000 asc
end
---@idGroupVehicle is null and @ResultCount is null
if @idGroupVehicle is null and @ResultCount is null
begin
select top 10 idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where (@start.STDistance(locationVehicle)/1000 <= 1)
order by @start.STDistance(locationVehicle)/1000 asc
end
--- @idGroupVehicle is null
if @idGroupVehicle is null
begin
select TOP(5) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where (@start.STDistance(locationVehicle)/1000 <= 1)
order by @start.STDistance(locationVehicle)/1000 asc
end
--- all options
else
begin
select TOP(5) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where idGroupVehicle= 1 and (@start.STDistance(locationVehicle)/1000 <= 1)
order by @start.STDistance(locationVehicle)/1000 asc
end
end
是否可以通过其他方式测试过程以显示执行时间和受影响的行,而不对过程进行任何更改?
您不必将您的程序转换为测试脚本。而只是 调用 它。并且不要使用冷过程或页面缓存进行测试。这是一个非常不寻常的状态。
SET STATISTICS IO, TIME ON
GO
declare @IdCustomer int = 1,
@idGroupVehicle int = null,
@ResultCount int= null,
@Radiant int= null
exec p_search_vehicle @IdCustomer, @idGroupVehicle, @ResultCount, @Radiant
GO
SET STATISTICS IO, TIME OFF