Merge branch '1.0.x' into 1.1.x
[luajson.git] / tests / timetrials.lua
blobb41ce2e9c7940cf3453b0aca46c1464728063f3e
1 --[[
2 Some Time Trails for the JSON4Lua package
3 ]]--
4 require('json')
5 require('os')
6 require('table')
8 local skipDecode = (...) == '--skipDecode'
9 local count = tonumber(select(2, ...) or 500) or 500
10 local strDup = tonumber(select(3, ...) or 1) or 1
11 local t1 = os.clock()
12 local jstr
13 local v
14 for i=1,count do
15 local t = {}
16 for j=1,500 do
17 t[#t + 1] = j
18 end
19 for j=1,500 do
20 t[#t + 1] = string.rep("VALUE", strDup)
21 end
22 jstr = json.encode(t)
23 if not skipDecode then v = json.decode(jstr) end
24 --print(json.encode(t))
25 end
27 for i = 1,count do
28 local t = {}
29 for j=1,500 do
30 local m= j % 4
31 local idx = string.rep('a'..j, strDup)
32 if (m==0) then
33 t[idx] = true
34 elseif m==1 then
35 t[idx] = json.util.null
36 elseif m==2 then
37 t[idx] = j
38 else
39 t[idx] = string.char(j % 0xFF)
40 end
41 end
42 jstr = json.encode(t)
43 if not skipDecode then v = json.decode(jstr) end
44 end
46 print (jstr)
47 --print(type(t1))
48 local t2 = os.clock()
50 print ("Elapsed time=" .. os.difftime(t2,t1) .. "s")