Repository navigation
Expand file tree
/
Copy pathtest07.lua
More file actions
61 lines (53 loc) · 1.67 KB
/
Copy pathtest07.lua
File metadata and controls
61 lines (53 loc) · 1.67 KB
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
local mtmsg = require("mtmsg")
local function printf(...)
print(string.format(...))
end
local N = 5000
local withName = false
local function printTime(title, startTime)
local t = mtmsg.time() - startTime
printf("%-15s %10.3f kop/sec, %6.3f msecs/op", title, N / t / 1000, t / N * 1000)
end
for run = 1, 2 do
collectgarbage()
printf("N = %d, withName = %s", N, tostring(withName))
local idlist = {}
local lslist = {}
--------------------------------------------------------------
local startTime = mtmsg.time()
do
for i = 1, N do
local b
if withName then
local name = "foo"..i or nil
b = mtmsg.newlistener(name)
else
b = mtmsg.newlistener()
end
lslist[i] = b
idlist[i] = b:id()
end
end
printTime("Creation:", startTime)
--------------------------------------------------------------
local startTime = mtmsg.time()
for i = 1, N do
assert(lslist[i]:id() == idlist[i])
end
printTime("Direct call:", startTime)
--------------------------------------------------------------
local startTime = mtmsg.time()
for i = 1, N do
local id = idlist[i]
assert(mtmsg.listener(id):id() == id)
end
printTime("Search by id:", startTime)
--------------------------------------------------------------
local startTime = mtmsg.time()
for i = 1, N do
assert(mtmsg.listener(idlist[i]):id() == idlist[i])
end
printTime("Call by id:", startTime)
--------------------------------------------------------------
end
print("OK.")