提交 b8bd744d 编写于 作者: T Thibault Charbonnier

docs(readme) add validation benchmarks

上级 b96889a3
......@@ -100,11 +100,16 @@ of dependencies.
Run `make bench` to run them:
```
LuaJIT 2.1.0-beta1
1e+06 uuids generated
1. FFI binding took: 0.103862s
2. C binding took: 0.224119s
3. Pure LuaJIT took: 0.792812s
4. Pure Lua took: 2.139352s
UUID generation (1e+06 UUIDs)
1. FFI binding took: 0.089645s
2. C binding took: 0.233015s
3. Pure LuaJIT took: 0.719925s
4. Pure Lua took: 2.045098s
UUID validation if provided (1e+06 UUIDs)
1. Pure LuaJIT (JIT PCRE enabled) took: 0.280195s
2. FFI binding took: 0.438504s
3. Pure LuaJIT (Lua patterns) took: 0.749306s
```
* FFI binding: <https://github.com/bungle/lua-resty-uuid>
......@@ -112,9 +117,6 @@ LuaJIT 2.1.0-beta1
* Pure Lua: <https://github.com/Tieske/uuid>
* Pure LuaJIT: this module
Note: uuid validation is not benchmarked yet (all of those modules do not
necessarily provide a way to validate uuids).
[Back to TOC](#table-of-contents)
### License
......
......@@ -4,22 +4,25 @@ end
package.path = "lib/?.lua;"..package.path
--local luuid = require "luuid"
local cuuid = require "lua_uuid" -- C binding
local lua_uuid = require "uuid" -- pure Lua
local ffi_uuid = require "resty.uuid" -- FFI binding
local luajit_uuid = require "resty.jit-uuid" -- Pure LuaJIT
local cuuid = require "lua_uuid"
local lua_uuid = require "uuid"
local ffi_uuid = require "resty.uuid"
local luajit_uuid = require "resty.jit-uuid"
local assert = assert
math.randomseed(os.time())
-------------
-- Generation
-------------
local res = {}
local uuids = {}
local n_uuids = 10^6
local tests = {
["Pure Lua"] = lua_uuid.new,
["Pure LuaJIT"]= luajit_uuid.generate,
--luuid = luuid.new,
["C binding"] = cuuid,
["FFI binding"] = ffi_uuid.generate
["FFI binding"] = ffi_uuid.generate_random
}
for k, uuid in pairs(tests) do
......@@ -33,7 +36,46 @@ end
table.sort(res, function(a, b) return a.time < b.time end)
print(jit.version)
print(string.format("%g uuids generated", n_uuids))
print(string.format("UUID generation (%g UUIDs)", n_uuids))
for i, result in ipairs(res) do
print(string.format("%d. %s\ttook:\t%fs", i, result.module, result.time))
end
-------------
-- Validation
-------------
if ngx then -- running in resty-cli
package.loaded["resty.jit-uuid"] = nil
ngx.config.nginx_configure = function() return "" end
local pattern_uuid = require "resty.jit-uuid"
tests = {
["FFI binding"] = ffi_uuid.is_valid,
["Pure LuaJIT (JIT PCRE enabled)"] = luajit_uuid.is_valid,
["Pure LuaJIT (Lua patterns)"] = pattern_uuid.is_valid
}
else
tests = {
["FFI binding"] = ffi_uuid.is_valid,
["Pure LuaJIT (Lua patterns)"] = luajit_uuid.is_valid
}
end
res = {}
for i = 1, n_uuids do
uuids[i] = luajit_uuid() -- we need v4 uuids to validate with our module
end
for k, validate in pairs(tests) do
local tstart = os.clock()
for i = 1, n_uuids do
assert(validate(uuids[i]))
end
res[#res+1] = {module = k, time = os.clock() - tstart}
end
table.sort(res, function(a, b) return a.time < b.time end)
print(string.format("\nUUID validation if provided (%g UUIDs)", n_uuids))
for i, result in ipairs(res) do
print(string.format("%d. %s\ttook:\t%fs", i, result.module, result.time))
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册