-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathmatch-prefix.lua
More file actions
45 lines (38 loc) · 1.17 KB
/
match-prefix.lua
File metadata and controls
45 lines (38 loc) · 1.17 KB
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
local radix = require("resty.radixtree")
local route_count = 1000 * 100
local match_times = 1000 * 1000
local routes = {}
for i = 1, route_count do
routes[i] = {paths = {"/" .. ngx.md5(i) .. "/*"}, metadata = i}
end
local rx = radix.new(routes)
ngx.say("case 1: route matched ")
ngx.update_time()
local start_time = ngx.now()
local res
local path = "/" .. ngx.md5(500) .. "/a"
for _ = 1, match_times do
res = rx:match(path)
end
ngx.update_time()
local used_time = ngx.now() - start_time
ngx.say("matched res: ", res)
ngx.say("route count: ", route_count)
ngx.say("match times: ", match_times)
ngx.say("time used : ", used_time, " sec")
ngx.say("QPS : ", math.floor(match_times / used_time))
ngx.say("=================")
ngx.say("case 2: route not matched ")
ngx.update_time()
start_time = ngx.now()
path = "/" .. ngx.md5(route_count + 1) .. "/a"
for _ = 1, match_times do
res = rx:match(path)
end
ngx.update_time()
local used_time = ngx.now() - start_time
ngx.say("matched res: ", res)
ngx.say("route count: ", route_count)
ngx.say("match times: ", match_times)
ngx.say("time used : ", used_time, " sec")
ngx.say("QPS : ", math.floor(match_times / used_time))