-
Notifications
You must be signed in to change notification settings - Fork 35
/
perf-test-match.sql
90 lines (63 loc) · 1.74 KB
/
perf-test-match.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
-- Performance test - RegexMatch()
*/
-- TEST 1: A SIMPLE REGEX MATCH
if object_id('tempdb..#results') is not null
begin
exec ('drop table #results');
end
go
declare @StartTime datetime, @EndTime datetime
set @StartTime = getdate();
;WITH x AS
(
SELECT TOP (1000) [object_id], name from sys.all_objects
)
SELECT n = ROW_NUMBER() OVER (ORDER BY x.[object_id])
,MatchedName = dbo.RegexMatch(x.name + y.name,'\w{4}')
into #results
FROM x CROSS JOIN x AS y ORDER BY n;
set @EndTime = getdate();
drop table #results;
select RunTimeInSec = datediff(ms, @StartTime,@EndTime) / 1000.0
go 10
-- TEST 2: A SLOWER, COMPLICATED REGEX MATCH
if object_id('tempdb..#results') is not null
begin
exec ('drop table #results');
end
go
declare @StartTime datetime, @EndTime datetime
set @StartTime = getdate();
;WITH x AS
(
SELECT TOP (1000) [object_id], name from sys.all_objects
)
SELECT n = ROW_NUMBER() OVER (ORDER BY x.[object_id])
,MatchedName = dbo.RegexMatch(x.name + y.name,'(\w*)\1')
into #results
FROM x CROSS JOIN x AS y ORDER BY n;
set @EndTime = getdate();
drop table #results;
select RunTimeInSec = datediff(ms, @StartTime,@EndTime) / 1000.0
go 10
-- TEST 3: PASS A NULL PATTERN, CHECK THE INVOCATION TIME
if object_id('tempdb..#results') is not null
begin
exec ('drop table #results');
end
go
declare @StartTime datetime, @EndTime datetime
set @StartTime = getdate();
;WITH x AS
(
SELECT TOP (1000) [object_id], name from sys.all_objects
)
SELECT n = ROW_NUMBER() OVER (ORDER BY x.[object_id])
,MatchedName = isnull(dbo.RegexMatch(x.name + y.name,null),x.name + y.name)
into #results
FROM x CROSS JOIN x AS y ORDER BY n;
set @EndTime = getdate();
drop table #results;
select RunTimeInSec = datediff(ms, @StartTime,@EndTime) / 1000.0
go 10