json.encode 100 万次, 耗时: 0.766102
json.decode 100 万次, 耗时: 1.504399
Last active
December 8, 2023 03:47
-
-
Save CandyMi/efdb327096e31633cab6ba8b5bf8e6c3 to your computer and use it in GitHub Desktop.
json 测试代码
This file contains hidden or 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
| 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