Skip to content

Instantly share code, notes, and snippets.

@CandyMi
Last active December 8, 2023 03:47
Show Gist options
  • Save CandyMi/efdb327096e31633cab6ba8b5bf8e6c3 to your computer and use it in GitHub Desktop.
Save CandyMi/efdb327096e31633cab6ba8b5bf8e6c3 to your computer and use it in GitHub Desktop.
json 测试代码

结果

json.encode 100 万次, 耗时: 0.766102
json.decode 100 万次, 耗时: 1.504399
local time = require "sys".now
require "utils"
local json = require "json"
local text = "我是\0車先生"
local tab = {
["na\0me"] = text,
n = 1 << 60,
f = math.pi,
b1 = true,
b2 = false,
b3 = null,
list = { 1.0, 2.0, 3.0 },
nan = 0/0,
inf = 1 / 0,
['-inf'] = -1 / 0,
}
local s, e
local n = 100
-- local j = json.encode(tab)
-- print (j)
-- var_dump(json.decode(j))
local function call(name, f, ...)
s = time()
for i = 1, n * 10000 do
f(...)
end
e = time()
print(string.format("%s %d 万次, 耗时: %f", name, n, e - s))
end
call('json.encode', json.encode, tab)
call('json.decode', json.decode, json.encode(tab))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment