Skip to content

Commit 1f83909

Browse files
committed
generate an html table in the benchmarks
1 parent 975250b commit 1f83909

4 files changed

Lines changed: 83 additions & 10 deletions

File tree

examples/benchmarks/incremental-KaSa/latex_table_compare_ws.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,37 @@ def main(inp_path, out_path):
8989
lines.append(" & ".join(row_elems) + r" \\")
9090
lines.append(r"\bottomrule")
9191
lines.append(r"\end{tabular}")
92-
9392
# write output
9493
with open(out_path, "w") as outf:
9594
outf.write("\n".join(lines))
9695

96+
# Build HTML
97+
lines = []
98+
lines.append("<table>")
99+
lines.append(" <tr>")
100+
lines.append(" <th>Nr. of rules in working set</th>")
101+
for step in all_steps:
102+
lines.append(" <th>" + step + "</th>")
103+
lines.append(" </tr>")
104+
105+
for test_instance in sorted(data.keys()):
106+
row_elems = []
107+
row_elems.append(latex_escape(test_instance))
108+
analysis_items = all_steps
109+
for s in analysis_items:
110+
val = data[test_instance].get(s, "")
111+
if val == "":
112+
row_elems.append("") # empty cell if missing
113+
else:
114+
row_elems.append(format_time(val))
115+
lines.append(" <tr>\n <td>" + "</td>\n <td>".join(row_elems) + "</td>\n </tr>")
116+
lines.append("</table>")
117+
# write output
118+
with open(out_path[:-4] + ".html", "w") as outf:
119+
outf.write("\n".join(lines))
120+
97121
if __name__ == "__main__":
98122
if len(sys.argv) < 3:
99-
print("Usage: python3 latex_table_of_runtimes.py input.csv output.tex")
123+
print("Usage: python3 latex_table_compare_ws.py input.csv output.tex")
100124
sys.exit(1)
101125
main(sys.argv[1], sys.argv[2])

examples/benchmarks/incremental-KaSa/latex_table_of_runtimes.py

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ def latex_escape(s: str) -> str:
3535
s = s.replace(k, v)
3636
return s
3737

38+
def html_escape(s: str) -> str:
39+
# minimal escaping for LaTeX special chars
40+
replace = {
41+
'\\': ' '
42+
}
43+
for k, v in replace.items():
44+
s = s.replace(k, v)
45+
return s
46+
3847
def format_time(t):
3948
# compact formatting: up to 3 significant digits
4049
try:
@@ -68,7 +77,13 @@ def main(inp_path, out_path):
6877
if model not in model_nr_rules:
6978
model_nr_rules[model] = nr_rules
7079

71-
total_step_count = 4
80+
# sort by number of rules in the model
81+
sorted_data = sorted(data.keys(), key=lambda k: int(model_nr_rules.get(k, "0")))
82+
83+
step_names = [r"analysis", r"initial\\analysis", r"disable\\rules", r"add\\a rule"]
84+
analysis_items = [("1_full",["1_init"]), ("2_decremental",["1_init", "4_disable"]), ("3_incremental",["1_init"])]
85+
86+
total_step_count = len(step_names)
7287
col_spec = "l c " + " ".join(["c"] * total_step_count)
7388

7489
# Build LaTeX
@@ -82,14 +97,14 @@ def main(inp_path, out_path):
8297
lines.append(r"\cmidrule(lr){3-3}")
8398
lines.append(r"\cmidrule(lr){4-6}")
8499
# Second header row
85-
lines.append(r"& & \bfseries\shortstack{analysis} & \bfseries\shortstack{initial\\analysis} & \bfseries\shortstack{disable\\rules} & \bfseries\shortstack{add\\a rule}\\")
100+
header = r"& & \bfseries\shortstack{" + r"} & \bfseries\shortstack{".join(step_names) + r"}\\"
101+
lines.append(header)
86102
lines.append(r"\midrule")
87103

88-
for model in sorted(data.keys(), key=lambda k: int(model_nr_rules.get(k, "0"))):# sort by number of rules in the model
104+
for model in sorted_data:
89105
row_elems = []
90106
row_elems.append(r"\texttt{" + latex_escape(model) + "}")
91107
row_elems.append(latex_escape(model_nr_rules.get(model, "")))
92-
analysis_items = [("1_full",["1_init"]), ("2_decremental",["1_init", "4_disable"]), ("3_incremental",["1_init"])]
93108
for a, steps in analysis_items:
94109
for s in steps:
95110
val = data[model].get(a, {}).get(s, "")
@@ -100,11 +115,41 @@ def main(inp_path, out_path):
100115
lines.append(" & ".join(row_elems) + r" \\")
101116
lines.append(r"\bottomrule")
102117
lines.append(r"\end{tabular}")
103-
104118
# write output
105119
with open(out_path, "w") as outf:
106120
outf.write("\n".join(lines))
107121

122+
# Build HTML
123+
lines = []
124+
lines.append("<table>")
125+
# First header row
126+
lines.append(" <tr>")
127+
lines.append(" <th rowspan=\"2\">Model</th>")
128+
lines.append(" <th rowspan=\"2\">Nr. of rules</th>")
129+
lines.append(" <th colspan=\"1\">non-incremental</th>")
130+
lines.append(" <th colspan=\"3\">incremental</th>")
131+
lines.append(" </tr>")
132+
# Second header row
133+
header = " <tr>\n <th>" + "</th>\n <th>".join([html_escape(step) for step in step_names]) + "</th>\n </tr>"
134+
lines.append(header)
135+
136+
for model in sorted_data:
137+
row_elems = []
138+
row_elems.append(model)
139+
row_elems.append(model_nr_rules.get(model, ""))
140+
for a, steps in analysis_items:
141+
for s in steps:
142+
val = data[model].get(a, {}).get(s, "")
143+
if val == "":
144+
row_elems.append("") # empty cell if missing
145+
else:
146+
row_elems.append(format_time(val))
147+
lines.append(" <tr>\n <td>" + "</td>\n <td>".join(row_elems) + "</td>\n </tr>")
148+
lines.append("</table>")
149+
# write output
150+
with open(out_path[:-4] + ".html", "w") as outf:
151+
outf.write("\n".join(lines))
152+
108153
if __name__ == "__main__":
109154
if len(sys.argv) < 3:
110155
print("Usage: python3 latex_table_of_runtimes.py input.csv output.tex")

examples/benchmarks/incremental-KaSa/script_compare_working_set_size

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
# or in output/experiments_output_compare_ws_plot.png (plot)
1212

1313
DEBUG=false
14-
VERBOSE=true
15-
INSTALL_DEPS=true
14+
VERBOSE=false
15+
INSTALL_DEPS=false
1616

1717
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1818
cd "${SCRIPT_DIR}/../../.."
@@ -255,6 +255,7 @@ echo
255255
echo "📝 The mean of all runtimes can be found in: $OUTPUT_MEAN_RUNTIMES"
256256

257257
OUTPUT_LATEX_RUNTIMES="${OUTPUT_DIR}experiments_output_compare_ws.tex"
258+
OUTPUT_HTML_RUNTIMES="${OUTPUT_DIR}experiments_output_compare_ws.html"
258259

259260
cmd=(python3
260261
"${SCRIPT_DIR}/latex_table_compare_ws.py"
@@ -267,6 +268,7 @@ fi
267268
{ ${cmd[@]}; }
268269

269270
echo "📊 The latex table of the runtimes can be found in: $OUTPUT_LATEX_RUNTIMES"
271+
echo "🕸️ The html table of the runtimes can be found in: $OUTPUT_HTML_RUNTIMES"
270272

271273
cmd=(python3
272274
"${SCRIPT_DIR}/plot.py" "${OUTPUT_DIR}experiments_output_mean.csv" "${OUTPUT_DIR}runtimes"

examples/benchmarks/incremental-KaSa/script_disable_and_add_rules

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,9 @@ echo
361361
echo "📝 The mean of all runtimes can be found in: $OUTPUT_MEAN_RUNTIMES"
362362

363363
OUTPUT_LATEX_RUNTIMES="${OUTPUT_DIR}experiments_output.tex"
364+
OUTPUT_HTML_RUNTIMES="${OUTPUT_DIR}experiments_output.html"
364365

365-
# draw a latex table with the runtimes
366+
# draw a latex and a html table with the runtimes
366367

367368
cmd=(python3
368369
"${SCRIPT_DIR}/latex_table_of_runtimes.py"
@@ -375,5 +376,6 @@ fi
375376
{ ${cmd[@]}; }
376377

377378
echo "📊 The latex table of the runtimes can be found in: $OUTPUT_LATEX_RUNTIMES"
379+
echo "🕸️ The html table of the runtimes can be found in: $OUTPUT_HTML_RUNTIMES"
378380

379381
deactivate

0 commit comments

Comments
 (0)