-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathbench_utils.lua
67 lines (59 loc) · 1.83 KB
/
bench_utils.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
require 'xlua'
local bench_utils = {}
-- Read the last line of a command line output handler
local read_last_line = function(handler)
-- hack to get the last line of a file
local last_line
for line in handler:lines() do
last_line = line
end
return last_line
end
-- Print one line to the output file
local print_one_result = function(output, command, accuracy)
output:write("| "..command.." | "..accuracy.." |\n")
end
-- Run the tests specified in params and write the results in the output file
-- Each element of params must contain:
-- el[1] = command line option
-- el[2] = table of the values to test
-- if the value is false, the option will not be use,
-- if the value is true, the option will be used without specific value
function bench_utils.run_test(params, output)
-- Add an empty line to the output file
print_one_result(output,'','')
-- Compute all the combinations
local arg_table
for _, param in pairs(params) do
local new_table = {}
for _, value in pairs(param[2]) do
local param_value_opt = ''
if value == true then
param_value_opt = param[1]
elseif value ~= false then
param_value_opt = param[1] .. value
end
if not arg_table then
table.insert(new_table, param_value_opt)
else
for _, arg in pairs(arg_table) do
table.insert(new_table, arg .. ' ' .. param_value_opt)
end
end
end
arg_table = new_table
end
-- Run the tests
local current = 0
for _,arg in pairs(arg_table) do
xlua.progress(current, #arg_table)
current = current + 1
local cmd = 'luajit main.lua --script ' .. arg
local handler = io.popen(cmd)
local accuracy = read_last_line(handler)
print_one_result(output, arg, accuracy)
end
-- Finish progress
xlua.progress(#arg_table, #arg_table)
end
return bench_utils