3 Star 3 Fork 2

Gitee 极速下载 / dkjson

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/LuaDist/dkjson
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
speedtest.lua 3.31 KB
一键复制 编辑 原始数据 按行查看 历史
Peter Drahoš 提交于 2013-03-05 15:13 . Imported from 2.2 rock
local encode, decode
local test_module = ... -- command line argument
--local test_module = 'cmj-json'
--local test_module = 'dkjson'
--local test_module = 'dkjson-nopeg'
--local test_module = 'fleece'
--local test_module = 'jf-json'
--locel test_module = 'lua-yajl'
--local test_module = 'mp-cjson'
--local test_module = 'nm-json'
--local test_module = 'sb-json'
--local test_module = 'th-json'
if test_module == 'cmj-json' then
-- http://json.luaforge.net/
local json = require "cmjjson" -- renamed, the original file was just 'json'
encode = json.encode
decode = json.decode
elseif test_module == 'dkjson' then
-- http://chiselapp.com/user/dhkolf/repository/dkjson/
local dkjson = require "dkjson"
encode = dkjson.encode
decode = dkjson.decode
elseif test_module == 'dkjson-nopeg' then
package.preload["lpeg"] = function () error "lpeg disabled" end
package.loaded["lpeg"] = nil
lpeg = nil
local dkjson = require "dkjson"
encode = dkjson.encode
decode = dkjson.decode
elseif test_module == 'fleece' then
-- http://www.eonblast.com/fleece/
local fleece = require "fleece"
encode = function(x) return fleece.json(x, "E4") end
elseif test_module == 'jf-json' then
-- http://regex.info/blog/lua/json
local json = require "jfjson" -- renamed, the original file was just 'JSON'
encode = function(x) return json:encode(x) end
decode = function(x) return json:decode(x) end
elseif test_module == 'lua-yajl' then
-- http://github.com/brimworks/lua-yajl
local yajl = require ("yajl")
encode = yajl.to_string
decode = yajl.to_value
elseif test_module == 'mp-cjson' then
-- http://www.kyne.com.au/~mark/software/lua-cjson.php
local json = require "cjson"
encode = json.encode
decode = json.decode
elseif test_module == 'nm-json' then
-- http://luaforge.net/projects/luajsonlib/
local json = require "LuaJSON"
encode = json.encode or json.stringify
decode = json.decode or json.parse
elseif test_module == 'sb-json' then
-- http://www.chipmunkav.com/downloads/Json.lua
local json = require "sbjson" -- renamed, the original file was just 'Json'
encode = json.Encode
decode = json.Decode
elseif test_module == 'th-json' then
-- http://luaforge.net/projects/luajson/
local json = require "json"
encode = json.encode
decode = json.decode
else
print "No module specified"
return
end
-- example data taken from
-- http://de.wikipedia.org/wiki/JavaScript_Object_Notation
local str = [[
{
"Herausgeber": "Xema",
"Nummer": "1234-5678-9012-3456",
"Deckung": 26,
"Währung": "EUR",
"Inhaber": {
"Name": "Mustermann",
"Vorname": "Max",
"männlich": true,
"Depot": {},
"Hobbys": [ "Reiten", "Golfen", "Lesen" ],
"Alter": 42,
"Kinder": [0],
"Partner": null
}
}
]]
local tbl = {
Herausgeber= "Xema",
Nummer= "1234-5678-9012-3456",
Deckung= 2e+6,
["Währung"]= "EUR",
Inhaber= {
Name= "Mustermann",
Vorname= "Max",
["männlich"]= true,
Depot= {},
Hobbys= { "Reiten", "Golfen", "Lesen" },
Alter= 42,
Kinder= {},
Partner= nil
--Partner= json.null
}
}
local t1, t2
if decode then
t1 = os.clock ()
for i = 1,100000 do
decode (str)
end
t2 = os.clock ()
print ("Decoding:", t2 - t1)
end
if encode then
t1 = os.clock ()
for i = 1,100000 do
encode (tbl)
end
t2 = os.clock ()
print ("Encoding:", t2 - t1)
end
Lua
1
https://gitee.com/mirrors/dkjson.git
git@gitee.com:mirrors/dkjson.git
mirrors
dkjson
dkjson
master

搜索帮助