-
Notifications
You must be signed in to change notification settings - Fork 35
/
perf-test-replace.sql
77 lines (55 loc) · 1.49 KB
/
perf-test-replace.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
/*
-- Performance test - RegexReplace()
*/
-- 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.RegexReplace(x.name + y.name,'(\w{5})(\w{2})','$2__$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 2: A COMPLEX 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.RegexReplace(x.name + y.name,'(\w{5})(\w{2})(\S+)','$2__$1__$3')
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
/*
;WITH x AS
(
SELECT TOP (1000) [object_id], name from sys.all_objects
)
SELECT n = ROW_NUMBER() OVER (ORDER BY x.[object_id])
--,x.name
--,y.name
,OriginalName = x.name + y.name
,MatchedName = dbo.RegexReplace(x.name + y.name,'(\w{5})(\w+)','$2__$1')
FROM x CROSS JOIN x AS y ORDER BY n;
*/