Created
January 7, 2014 18:20
-
-
Save Phrogz/8303990 to your computer and use it in GitHub Desktop.
This file contains 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 lua = [[{ | |
["hello"]="there\nworld", | |
["array"]={1,2,3,1e6,{["more"]=false},nil,true}, | |
["more"]={ | |
["hello"]="there\nworld", | |
["array"]={1,2,3,1e6,{["more"]=false},nil,true}, | |
["more"]={ | |
["hello"]="there\nworld", | |
["array"]={1,2,3,1e6,{["more"]=false},nil,true}, | |
["more"]={ | |
["hello"]="there\nworld", | |
["array"]={1,2,3,1e6,{["more"]="\"And\" \"actually,\" \"doesn't\" \"hurt\" \"to\" \"benchmark\" \"both,\" \"huh?\" \":)\""},nil,true} | |
} | |
} | |
} | |
}]] | |
local json = lua:gsub('%["','"'):gsub('"%]','"'):gsub('=',':'):gsub('nil','null'):gsub('{1','[1'):gsub('true}','true]') | |
N = 100000 | |
local start = os.clock() | |
for i=1,N do loadstring('return '..lua)() end | |
local duration = os.clock() - start | |
print("Lua native:",duration,"seconds") --> 3.009 seconds | |
-- Using https://github.com/harningt/luajson v1.3.2 | |
package.path = package.path .. ';./luajson/lua/?.lua' | |
local JSON = require 'json' | |
local start = os.clock() | |
for i=1,N do JSON.decode(json) end | |
local duration = os.clock() - start | |
print("LuaJSON:",duration,"seconds") --> 16.925 seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment