decoder: fixes compatibility with lpeg 0.12 by closing off 0-length captures in loops
[luajson.git] / tests / timetrials.lua
blob1ffa121ee6737383d275026ab2ba81331deb0445
1 --[[
2 Some Time Trails for the JSON4Lua package
3 ]]--
5 require('json')
6 local os = require('os')
7 local table = require('table')
8 local string = require("string")
10 local skipDecode = (...) == '--skipDecode'
11 local count = tonumber(select(2, ...) or 500) or 500
12 local strDup = tonumber(select(3, ...) or 1) or 1
13 local t1 = os.clock()
14 local jstr
15 local v
16 for i=1,count do
17 local t = {}
18 for j=1,500 do
19 t[#t + 1] = j
20 end
21 for j=1,500 do
22 t[#t + 1] = string.rep("VALUE", strDup)
23 end
24 jstr = json.encode(t)
25 if not skipDecode then v = json.decode(jstr) end
26 --print(json.encode(t))
27 end
29 for i = 1,count do
30 local t = {}
31 for j=1,500 do
32 local m= j % 4
33 local idx = string.rep('a'..j, strDup)
34 if (m==0) then
35 t[idx] = true
36 elseif m==1 then
37 t[idx] = json.util.null
38 elseif m==2 then
39 t[idx] = j
40 else
41 t[idx] = string.char(j % 0xFF)
42 end
43 end
44 jstr = json.encode(t)
45 if not skipDecode then v = json.decode(jstr) end
46 end
48 print (jstr)
49 --print(type(t1))
50 local t2 = os.clock()
52 print ("Elapsed time=" .. os.difftime(t2,t1) .. "s")