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()