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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
local METHODS = {
"copy", "sse2", "invb", "lutb", "lut", "inv", --"div"
}
local DATAS = {
"random", "random solid", "clear"
}
local SIZES = {}
for i=1,5 do table.insert(SIZES, 64*8^i) end
local function sample(method, data, size)
local total = 20 * 16777216
local loops = math.ceil(total / size)
local cmd = table.concat({
("loops=%.0f pixels=%d offset=0"):format(loops, size),
"./unpremultiply",
data, method
}, " ")
print(cmd)
local pipe = assert(io.popen(cmd, "r"))
local line = pipe:read()
local time_in_ms = assert(tonumber(line))
pipe:close()
print(method, data, size, time_in_ms)
return time_in_ms
end
local tab = {
w = 0,
h = 1,
j = 1,
cells = setmetatable({},
{
__index = function (t,i)
local v = {}
rawset(t,i,v)
return v
end,
})
}
local function cr()
tab.h = tab.h+1
tab.j = 1
end
local function td(entry)
local i = tab.h
local j = tab.j
tab.cells[i][j] = entry and tostring(entry) or nil
if tab.w < j then
tab.w = j
end
tab.j = j + 1
end
td("Data")
td("Pixels")
for i,m in ipairs(METHODS) do td(m) end
cr()
for _,data in ipairs(DATAS) do
cr()
for _,size in ipairs(SIZES) do
local times = {}
td(data)
td(size)
for i,m in ipairs(METHODS) do
times[i] = sample(m, data, size)
end
for i,m in ipairs(METHODS) do
td(("%.3f"):format(times[i] / times[1]))
end
cr()
end
end
local function show()
local formats = {}
local cells = {}
local ncol = tab.w
local nrow = tab.h
for j=1,ncol do
local maxw = 0
for i=1,nrow do
local eij = tab.cells[i][j] or ""
maxw = #eij < maxw and maxw or #eij
end
formats[j] = ("%%%ds"):format(maxw)
end
for i=1,nrow do
for j=1,ncol do
local eij = tab.cells[i][j] or ""
if j > 1 then io.write" | " end
io.write(formats[j]:format(eij))
end
io.write"\n"
end
end
show()
|