diff options
author | M Joonas Pihlaja <jpihlaja@cc.helsinki.fi> | 2009-01-14 23:38:37 +0200 |
---|---|---|
committer | M Joonas Pihlaja <jpihlaja@cc.helsinki.fi> | 2009-01-14 23:38:37 +0200 |
commit | d7dcc30c1626f488efab6bd4dd028571968d2815 (patch) | |
tree | 41d129d096bc2f5cb70a511b7340d3cce9496f81 | |
parent | 2336c8788dea7209e4bc582f0f7c8cf163edf589 (diff) |
Added bench.lua
-rw-r--r-- | bench.lua | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/bench.lua b/bench.lua new file mode 100644 index 0000000..79d4444 --- /dev/null +++ b/bench.lua @@ -0,0 +1,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()
\ No newline at end of file |