Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Ip2region
提交
85d955b5
I
Ip2region
项目概览
int
/
Ip2region
上一次同步 大约 1 年
通知
20
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
Ip2region
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
85d955b5
编写于
7月 02, 2022
作者:
L
Lion
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bench test script ready and bench test passed
上级
ed955a44
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
164 addition
and
2 deletion
+164
-2
binding/lua_c/bench_test.lua
binding/lua_c/bench_test.lua
+164
-0
binding/lua_c/search_test.lua
binding/lua_c/search_test.lua
+0
-2
未找到文件。
binding/lua_c/bench_test.lua
浏览文件 @
85d955b5
...
...
@@ -5,3 +5,167 @@
-- ---
-- @Author Lion <chenxin619315@gmail.com>
-- @Date 2022/06/30
local
xdb
=
require
(
"xdb_searcher"
)
function
printHelp
()
print
(
"lua bench_test.lua [command options]"
)
print
(
"options: "
)
print
(
" --db string ip2region binary xdb file path"
)
print
(
" --src string source ip text file path"
)
print
(
" --cache-policy string cache policy: file/vectorIndex/content"
)
end
if
#
arg
<
2
then
printHelp
(
arg
)
return
end
-- parser the command line args
local
dbFile
,
srcFile
=
""
,
""
local
cachePolicy
=
"vectorIndex"
for
_
,
r
in
ipairs
(
arg
)
do
if
string.len
(
r
)
<
5
then
goto
continue
end
if
string.sub
(
r
,
1
,
2
)
~=
"--"
then
goto
continue
end
for
k
,
v
in
string.gmatch
(
string.sub
(
r
,
3
),
"([^=]+)=([^%s]+)"
)
do
if
k
==
"db"
then
dbFile
=
v
elseif
k
==
"src"
then
srcFile
=
v
elseif
k
==
"cache-policy"
then
cachePolicy
=
v
end
-- break the match iterate
break
end
-- continue this loop
::
continue
::
end
-- print(string.format("dbFile=%s, srcFile=%s, cachePolicy=%s", dbFile, srcFile, cachePolicy))
if
string.len
(
dbFile
)
<
2
or
string.len
(
srcFile
)
<
2
then
printHelp
()
return
end
-- create the searcher based on the cache-policy
local
searcher
,
v_index
,
content
if
cachePolicy
==
"file"
then
searcher
=
xdb
.
new_with_file_only
(
dbFile
)
elseif
cachePolicy
==
"vectorIndex"
then
v_index
=
xdb
.
load_vector_index
(
dbFile
)
if
v_index
==
nil
then
print
(
string.format
(
"failed to load vector index from '%s'"
,
dbFile
))
return
end
searcher
,
err
=
xdb
.
new_with_vector_index
(
dbFile
,
v_index
)
if
err
~=
nil
then
print
(
string.format
(
"failed to create vector index searcher: %s"
,
err
))
return
end
elseif
cachePolicy
==
"content"
then
content
=
xdb
.
load_content
(
dbFile
)
if
content
==
nil
then
print
(
string.format
(
"failed to load xdb content from '%s'"
,
dbFile
))
return
end
searcher
,
err
=
xdb
.
new_with_buffer
(
content
)
if
err
~=
nil
then
print
(
string.format
(
"failed to create content buffer searcher: %s"
,
err
))
return
end
else
print
(
string.format
(
"undefined cache-policy `%s`"
,
cachePolicy
))
return
end
-- do the bench test
local
handle
=
io.open
(
srcFile
,
"r"
)
if
handle
==
nil
then
print
(
string.format
(
"failed to open src text file `%s`"
,
handle
))
return
end
local
lines
=
handle
:
lines
()
local
sip_str
,
eip_str
,
s_region
,
region
=
""
,
""
,
""
,
""
local
sip
,
mip
,
eip
,
err
=
0
,
0
,
0
,
0
local
count
,
t_time
,
c_time
=
0
,
0
,
0
local
s_time
=
xdb
.
now
()
for
l
in
lines
do
if
string.len
(
l
)
<
1
then
goto
continue
end
for
v1
,
v2
,
v3
in
string.gmatch
(
l
,
"([%d%.]+)|([%d%.]+)|([^\n]+)"
)
do
-- print(sip_str, eip_str, region)
sip_str
=
v1
eip_str
=
v2
s_region
=
v3
break
end
sip
,
err
=
xdb
.
check_ip
(
sip_str
)
if
err
~=
nil
then
print
(
string.format
(
"invalid start ip `%s`"
,
sip_str
))
return
end
eip
,
err
=
xdb
.
check_ip
(
eip_str
)
if
err
~=
nil
then
print
(
string.format
(
"invalid end ip `%s`"
,
sip_str
))
return
end
if
sip
>
eip
then
print
(
string.format
(
"start ip(%s) should not be greater than end ip(%s)\n"
,
sip_str
,
eip_str
))
return
end
mip
=
(
sip
+
eip
)
>>
1
for
_
,
ip
in
ipairs
({
sip
,
(
sip
+
mip
)
>>
1
,
mip
,
(
mip
+
eip
)
>>
1
,
eip
})
do
t_time
=
xdb
.
now
()
region
,
err
=
searcher
:
search
(
ip
)
c_time
=
c_time
+
xdb
.
now
()
-
t_time
if
err
~=
nil
then
print
(
string.format
(
"failed to search ip `%s`"
,
xdb
.
long2ip
(
ip
)))
return
end
-- check the region
if
region
~=
s_region
then
printf
(
string.format
(
"failed search(%s) with (%s != %s)\n"
,
xdb
.
long2ip
(
ip
),
region
,
s_region
))
return
end
count
=
count
+
1
end
::
continue
::
end
-- resource cleanup
searcher
:
close
()
if
v_index
~=
nil
then
v_index
:
close
()
end
if
content
~=
nil
then
content
:
close
()
end
-- print the stats
local
avg_costs
=
0
if
count
>
0
then
avg_costs
=
c_time
/
count
end
print
(
string.format
(
"Bench finished, {cachePolicy: %s, total: %d, took: %.3f s, cost: %.3f μs/op}"
,
cachePolicy
,
count
,
(
xdb
.
now
()
-
s_time
)
/
1e6
,
c_time
/
count
))
binding/lua_c/search_test.lua
浏览文件 @
85d955b5
...
...
@@ -125,11 +125,9 @@ end
-- resource cleanup
searcher
:
close
()
if
v_index
~=
nil
then
v_index
:
close
()
end
if
content
~=
nil
then
content
:
close
()
end
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录