-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.lua
50 lines (39 loc) · 1.23 KB
/
bench.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
local bottom = require("bottom")
local encode, decode = bottom.encode, bottom.decode
local tests
do
local json, io = require("json"), require("io")
local file = io.open("testing.json", "rb")
if not file then error("testing.json not detected") end
tests = json.decode(file:read("*a"))
file:close()
end
local iterations = 100000
local sformat = string.format
local function format(t) return sformat("%dns", t / iterations * 1e9) end
local clock = os.clock
for i, o in pairs(tests.encode) do
print("Encoding<" .. #i .. ">:")
if encode(i) == o then
print("\tResult: PASS")
local start = clock()
for i = 1, iterations do encode(i) end
print("\tEach iteration of " .. iterations .. " iterations took " ..
format(clock() - start))
else
print("\tResult: FAILURE")
end
end
print()
for i, o in pairs(tests.decode) do
print("Decoding<" .. #o .. ">:")
if decode(i) == o then
print("\tResult: PASS")
local start = clock()
for i = 1, iterations do decode(i) end
print("\tEach iteration of " .. iterations .. " iterations took " ..
format(clock() - start))
else
print("\tResult: FAILURE")
end
end