标签:项目 因此 自己 实验 lob style pre 频率 存在
以上两种场景中,json和table的互转使用频率是非常高的,如果转换效率有提升,对于降低我们业务延时将会有很大的帮助。因此,选择一种高效率的转换方式的重要性可见一斑。
下面我们简单介绍两种转换方式,并对他们的转换效率做一个对比。
local t = { a = "hello", b = "world", c = 123456, d = "123456", e = {"hhh", "11", "22"}, f = { a = "hello", b = "world", c = 123456, d = "123456", e = {"hhh", "11", "22"}, count = 0 } } local tm1 = os.time() local str_json = "" for i = 1, 50000, 1 do --str_json = json.encode(t) --t = json.decode(str_json) str_json = cjson.encode(t) t = cjson.decode(str_json) t.f.count = t.f.count + 1 end local tm2 = os.time() print("tm1:" .. tm1 .. ",tm2:" .. tm2 .. ",dt:" .. (tm2 - tm1)) print(str_json)
tm1:1575363384,tm2:1575363435,dt:51 {"a":"hello","c":123456,"b":"world","e":["hhh","11","22"],"d":"123456","f":{"a":"hello","c":123456,"b":"world","e":["hhh","11","22"],"d":"123456","count":49999}}
tm1:1575363457,tm2:1575363462,dt:5 {"a":"hello","c":123456,"b":"world","e":["hhh","11","22"],"d":"123456","f":{"a":"hello","c":123456,"b":"world","e":["hhh","11","22"],"d":"123456","count":49999}}
标签:项目 因此 自己 实验 lob style pre 频率 存在
原文地址:https://www.cnblogs.com/shxyhld/p/11980277.html