-
Notifications
You must be signed in to change notification settings - Fork 11
/
bench.lua
76 lines (61 loc) · 1.81 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
local mp = require "./msgpack"
--local mpo = require "./orig_mplua/msgpackorig"
local os = require "os"
local table = require "table"
local unp = mp.createUnpacker(1024*1024)
local nLoop = 3000
function makeiary(n)
local out={}
for i=1,n do table.insert(out,i) end
return out
end
function makestr(n)
local out=""
for i=1,n-1 do out = out .. "a" end
out = out .. "b"
return out
end
local datasets = {
{ "empty", nLoop*1000, {} },
{ "iary1", nLoop*1000, {1} },
{ "iary10", nLoop*100, {1,2,3,4,5,6,7,8,9,10} },
{ "iary100", nLoop*10, makeiary(100) },
{ "iary1000", nLoop*10, makeiary(1000) },
{ "iary10000", nLoop, makeiary(10000) },
{ "str1", nLoop*1000, "a" },
{ "str10", nLoop*1000, makestr(10) },
{ "str100", nLoop*1000, makestr(100) },
{ "str500", nLoop*1000, makestr(500) },
{ "str1000", nLoop*1000, makestr(1000) },
{ "str10000", nLoop*100, makestr(10000) },
}
for i,v in ipairs(datasets) do
-- lua-msgpack-native
st = os.clock()
local nLoop = v[2]
local offset,res
for j=1, nLoop do
offset,res = mp.unpack( mp.pack(v[3] ) )
end
assert(offset)
local et = os.clock()
local mptime = et - st
-- lua-msgpack-native streaming api (one bulk feed)
st = os.clock()
for j=1, nLoop do
unp:feed( mp.pack(v[3]) )
unp:pull()
end
et = os.clock()
local mpstime = et - st
-- original pure lua msgpack
-- st = os.clock()
-- for j=1, nLoop do
-- offset,res = mpo.unpack( mpo.pack( v[3] ) )
-- end
-- assert(offset)
-- et = os.clock()
-- local mpotime = et - st
-- print( "mp:", v[1], mptime, "sec", "native:", nLoop/mptime, "stream:", nLoop/mpstime, "orig:", nLoop/mpotime, "(times/sec)", (mpotime/mptime), "times faster")
print( "mp:", v[1], mptime, "sec", "native:", nLoop/mptime, "stream:", nLoop/mpstime )
end