-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
536 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
local radix = require("router-tree") | ||
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.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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,79 @@ | ||
--require 'busted.runner'() | ||
require 'busted.runner'() | ||
|
||
local trie = require "router-tree.trie" | ||
local Trie = require "router-tree.trie" | ||
local cjson = require "cjson" | ||
local inspect = require "inspect" | ||
|
||
--describe("test cases from httprouter", function() | ||
-- it("test1", function() | ||
-- local paths = { | ||
-- "/hi", | ||
-- "/contact", | ||
-- "/co", | ||
-- "/c", | ||
-- --"/a", | ||
-- --"/ab", | ||
-- --"/doc/", | ||
-- --"/doc/go_faq.html", | ||
-- --"/doc/go1.html", | ||
-- --"/α", | ||
-- --"/β", | ||
-- } | ||
-- local mobdebug = require "mobdebug" | ||
-- mobdebug.start("localhost", 28172) | ||
-- local root = trie.new() | ||
-- for _, path in ipairs(paths) do | ||
-- root:add(path) | ||
-- end | ||
-- print(inspect(root)) | ||
-- end) | ||
--end) | ||
describe("Trie", function() | ||
it("", function() | ||
local root = Trie.new() | ||
root:add("key", "value") | ||
assert.equal("key", root.path) | ||
assert.equal("value", root.value) | ||
end) | ||
|
||
it("", function() | ||
local root = Trie.new() | ||
root:add("cat", "cat") | ||
root:add("dog", "dog") | ||
--print(inspect(root)) | ||
--print(cjson.encode(root)) | ||
end) | ||
|
||
local function test1() | ||
local paths = { | ||
"/hi", | ||
"/contact", | ||
"/co", | ||
"/c", | ||
"/a", | ||
"/ab", | ||
"/doc/", | ||
"/doc/go_faq.html", | ||
"/doc/go1.html", | ||
--"/α", | ||
--"/β", | ||
} | ||
local mobdebug = require "mobdebug" | ||
mobdebug.start("localhost", 28172) | ||
local root = trie.new() | ||
for _, path in ipairs(paths) do | ||
root:add(path, path) | ||
end | ||
it("需要修复", function() | ||
local root = Trie.new() | ||
root:add("/:name/foo", "1") | ||
root:add("/:name/foo*", "2") | ||
end) | ||
|
||
local requests = { | ||
{"/a", "/a" }, | ||
{"/", nil }, | ||
{"/hi", "/hi" }, | ||
{"/contact", "/contact" }, | ||
{"/co", "/co" }, | ||
{"/con", nil }, | ||
{"/cona", nil }, | ||
{"/no", nil }, | ||
{"/ab", "/ab" }, | ||
--{"/α", "/α" }, | ||
--{"/β", "/β" }, | ||
} | ||
for _, request in ipairs(requests) do | ||
local v = root:get(request[1]) | ||
assert(request[2] == v) | ||
end | ||
--print(inspect(root)) | ||
end | ||
it("sanity", function() | ||
local paths = { | ||
"/hi", | ||
"/contact", | ||
"/co", | ||
"/c", | ||
"/a", | ||
"/ab", | ||
"/doc/", | ||
"/doc/go_faq.html", | ||
"/doc/go1.html", | ||
--"/α", | ||
--"/β", | ||
} | ||
local root = Trie.new() | ||
for _, path in ipairs(paths) do | ||
root:add(path, path) | ||
end | ||
|
||
local function test2() | ||
local paths = { | ||
"/user1/:name", | ||
"/user2/:name", | ||
"/user3/:name", | ||
"/user4/:name", | ||
} | ||
local mobdebug = require "mobdebug" | ||
mobdebug.start("localhost", 28172) | ||
local root = trie.new() | ||
for _, path in ipairs(paths) do | ||
root:add(path, path) | ||
end | ||
local requests = { | ||
{ "/a", "/a" }, | ||
{ "/", nil }, | ||
{ "/hi", "/hi" }, | ||
{ "/contact", "/contact" }, | ||
{ "/co", "/co" }, | ||
{ "/con", nil }, | ||
{ "/cona", nil }, | ||
{ "/no", nil }, | ||
{ "/ab", "/ab" }, | ||
--{"/α", "/α" }, | ||
--{"/β", "/β" }, | ||
} | ||
for _, request in ipairs(requests) do | ||
local v = root:traverse(request[1]) | ||
assert(request[2] == v) | ||
end | ||
--print(inspect(root)) | ||
end) | ||
end) | ||
|
||
print(root:get("/user4/doge")) | ||
end | ||
|
||
-- test params | ||
local function test3() | ||
|
||
local function test1() | ||
local mobdebug = require "mobdebug" | ||
mobdebug.start("localhost", 28172) | ||
local root = Trie.new() | ||
root:add("/:name/foo", "1") | ||
root:add("/:name/foo*", "2") | ||
print("doge") | ||
end | ||
|
||
--test1() | ||
test2() | ||
test1() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-- TODO |
Oops, something went wrong.