-
Notifications
You must be signed in to change notification settings - Fork 10
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
14 changed files
with
303 additions
and
1,715 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
build: | ||
luarocks make | ||
|
||
test: | ||
busted spec | ||
test: build | ||
luajit spec/utils_spec.lua | ||
|
||
bench: build | ||
resty -I=./lib -I=./deps/share/lua/5.1 benchmark/match-parameter.lua | ||
|
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,28 @@ | ||
local radix = require("router-tree") | ||
local route_count = 1000 * 100 | ||
local match_times = 1000 * 1000 * 10 | ||
|
||
local routes = {} | ||
for i = 1, route_count do | ||
routes[i] = {paths = {"/user" .. i .. "/:name"}, handler = i} | ||
end | ||
|
||
local rx = radix.new(routes) | ||
|
||
ngx.update_time() | ||
local start_time = ngx.now() | ||
|
||
local res | ||
local path = "/user1/gordon" | ||
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("each time : ", used_time * 1000 * 1000 / match_times, " ns") |
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,28 @@ | ||
local radix = require("router-tree") | ||
local route_count = 1000 * 100 | ||
local match_times = 1000 * 1000 * 10 | ||
|
||
local routes = {} | ||
for i = 1, route_count do | ||
routes[i] = {paths = {"/user" .. i .. "/:name/a/b/c/d/e/f/g/h/i/j/k/l"}, handler = i} | ||
end | ||
|
||
local rx = radix.new(routes) | ||
|
||
ngx.update_time() | ||
local start_time = ngx.now() | ||
|
||
local res | ||
local path = "/user1/gordon/a/b/c/d/e/f/g/h/i/j/k/l" | ||
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("each time : ", used_time * 1000 * 1000 / match_times, " ns") |
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 * 10 | ||
|
||
local routes = {} | ||
for i = 1, route_count do | ||
routes[i] = {paths = {"/" .. ngx.md5(i)}, handler = i} | ||
end | ||
|
||
local rx = radix.new(routes) | ||
|
||
ngx.update_time() | ||
local start_time = ngx.now() | ||
|
||
local res | ||
local path = "/" .. ngx.md5(500) | ||
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
local package_name = "lua-resty-router-tree" | ||
local package_version = "dev" | ||
local rockspec_revision = "1" | ||
local github_account_name = "vm-001" | ||
local github_repo_name = "lua-resty-router-tree" | ||
local git_checkout = package_version == "dev" and "master" or ("version_"..package_version) | ||
|
||
package = package_name | ||
version = package_version .. "-" .. rockspec_revision | ||
|
||
source = { | ||
url = "git+https://github.com/"..github_account_name.."/"..github_repo_name..".git", | ||
branch = git_checkout | ||
} | ||
|
||
description = { | ||
summary = "lua-resty-router-tree module for Lua 5.x", | ||
detailed = [[ | ||
]], | ||
license = "MIT", | ||
homepage = "https://github.com/"..github_account_name.."/"..github_repo_name, | ||
} | ||
|
||
dependencies = { | ||
"lua >= 5.0, < 5.5" | ||
} | ||
|
||
build = { | ||
type = "builtin", | ||
modules = { | ||
["router-tree"] = "src/resty/router.lua", | ||
["router-tree.parser"] = "src/resty/parser.lua", | ||
["router-tree.trie"] = "src/resty/trie.lua", | ||
["router-tree.utils"] = "src/resty/utils.lua", | ||
}, | ||
} |
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,5 +1,5 @@ | ||
|
||
--local router = require "router" | ||
local router = require "router-tree" | ||
|
||
describe("router", function() | ||
|
||
|
Empty file.
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,91 @@ | ||
--require 'busted.runner'() | ||
|
||
local trie = require "router-tree.trie" | ||
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) | ||
|
||
|
||
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 | ||
|
||
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 | ||
|
||
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 | ||
|
||
print(root:get("/user4/doge")) | ||
end | ||
|
||
--test1() | ||
test2() |
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,15 @@ | ||
require 'busted.runner'() | ||
|
||
local utils = require "router-tree.utils" | ||
|
||
describe("utils", function() | ||
it("starts_with", function() | ||
assert.is_true(utils.starts_with("/abc", "/")) | ||
assert.is_true(utils.starts_with("/abc", "/a")) | ||
assert.is_true(utils.starts_with("/abc", "/ab")) | ||
assert.is_true(utils.starts_with("/abc", "/abc")) | ||
|
||
assert.is_false(utils.starts_with("/abc", "/abcd")) | ||
assert.is_false(utils.starts_with("/abc", "/d")) | ||
end) | ||
end) |
Oops, something went wrong.