clean whitespace

This commit is contained in:
goksu 2023-09-18 14:46:47 +03:00
parent f2c7d4bf89
commit 210471bcc6
No known key found for this signature in database
3 changed files with 111 additions and 105 deletions

View File

@ -6,7 +6,6 @@ FTBENCH_BIN = $(OBJ_DIR)/bench$E
INCLUDES = $(TOP_DIR)/include
FONTS = $(wildcard $(FTBENCH_DIR)/fonts/*.ttf)
# Define objects.
BASELINE_DIR = $(OBJ_DIR)/baseline/
BENCHMARK_DIR = $(OBJ_DIR)/benchmark/
@ -17,8 +16,7 @@ HTMLCREATOR = $(OBJ_DIR)/tohtml.py
HTMLFILE = $(OBJ_DIR)/benchmark.html
# Define flags by default
FTBENCH_FLAG ?= -c 1000 -w 100
FTBENCH_FLAG ?= -c 100 -w 10
# Define test fonts all in the fonts folder.
BASELINE = $(addprefix $(BASELINE_DIR), $(notdir $(FONTS:.ttf=.txt)))

View File

@ -42,8 +42,6 @@ INFO_1 = "* Average time for single iteration. Smaller values are better."
INFO_2 = "* If a value in the 'Iterations' column is given as '<i>x | y</i>', values <i>x</i> and <i>y</i> give the number of iterations in the baseline and the benchmark test, respectively."
def main():
"""Entry point for theq script"""
with open(BENCHMARK_HTML, "w") as html_file:
@ -76,10 +74,10 @@ def main():
html_file, baseline_results, benchmark_results, filename
)
write_to_html(html_file, "<center>Freetype Benchmark</center>\n")
write_to_html(html_file, "</body>\n</html>\n")
def write_to_html(html_file, content):
"""Write content to html file"""
html_file.write(content)
@ -94,7 +92,7 @@ def read_file(file_path):
def parse_info_file(info_file):
"""Get info from info.txt file and return as list"""
info = read_file(info_file)
info[1] = '<a href="{}{}">{}</a>\n'.format(GITLAB_URL, info[1].strip(), info[1][:8])
info[1] = f'<a href="{GITLAB_URL}{info[1].strip()}">{info[1][:8]}</a>\n'
return info
@ -111,9 +109,7 @@ def generate_info_table(html_file, baseline_info, benchmark_info):
):
write_to_html(
html_file,
'<tr><td class="col1">{}</td><td>{}</td><td>{}</td></tr>\n'.format(
info, baseline_line.strip(), benchmark_line.strip()
),
f'<tr><td class="col1">{info}</td><td>{baseline_line.strip()}</td><td>{benchmark_line.strip()}</td></tr>\n'
)
write_to_html(html_file, "</table><br/>")
write_to_html(html_file, f"<p>{INFO_1}</p>")
@ -124,22 +120,36 @@ def generate_total_results_table(html_file, baseline_dir, benchmark_dir):
"""Prepare total results table for html"""
# This dictionary will store aggregated results.
test_results = {test: {"baseline": 0, "benchmark": 0, "n_baseline": 0, "n_benchmark": 0} for test in [
"Load", "Load_Advances (Normal)", "Load_Advances (Fast)", "Load_Advances (Unscaled)", "Render",
"Get_Glyph", "Get_Char_Index", "Iterate CMap", "New_Face", "Embolden", "Stroke", "Get_BBox",
"Get_CBox", "New_Face & load glyph(s)"
]}
test_results = {
test: {"baseline": 0, "benchmark": 0, "n_baseline": 0, "n_benchmark": 0}
for test in [
"Load",
"Load_Advances (Normal)",
"Load_Advances (Fast)",
"Load_Advances (Unscaled)",
"Render",
"Get_Glyph",
"Get_Char_Index",
"Iterate CMap",
"New_Face",
"Embolden",
"Stroke",
"Get_BBox",
"Get_CBox",
"New_Face & load glyph(s)",
]
}
total_time = 0
for filename in os.listdir(baseline_dir):
if filename.endswith(".txt") and not filename == "info.txt":
baseline_results = read_file(os.path.join(baseline_dir, filename))
benchmark_results = read_file(os.path.join(benchmark_dir, filename))
for baseline_line, benchmark_line in zip(baseline_results, benchmark_results):
for baseline_line, benchmark_line in zip(
baseline_results, benchmark_results
):
if baseline_line.startswith("Total time:"):
baseline_match = re.match(r"Total time: (\d+)s", baseline_line)
benchmark_match = re.match(r"Total time: (\d+)s", benchmark_line)
@ -148,10 +158,14 @@ def generate_total_results_table(html_file, baseline_dir, benchmark_dir):
total_time += int(baseline_match.group(1))
total_time += int(benchmark_match.group(1))
if baseline_line.startswith(" "):
baseline_match = re.match(r"\s+(.*?)\s+(\d+\.\d+)\s+microseconds\s+(\d+)\s", baseline_line)
benchmark_match = re.match(r"\s+(.*?)\s+(\d+\.\d+)\s+microseconds\s+(\d+)\s", benchmark_line)
baseline_match = re.match(
r"\s+(.*?)\s+(\d+\.\d+)\s+microseconds\s+(\d+)\s", baseline_line
)
benchmark_match = re.match(
r"\s+(.*?)\s+(\d+\.\d+)\s+microseconds\s+(\d+)\s",
benchmark_line,
)
if baseline_match and benchmark_match:
test = baseline_match.group(1).strip()
@ -167,29 +181,34 @@ def generate_total_results_table(html_file, baseline_dir, benchmark_dir):
test_results[test]["n_baseline"] += baseline_n
test_results[test]["n_benchmark"] += benchmark_n
# Writing to HTML
write_to_html(html_file, "<h2>Total Results</h2>\n")
write_to_html(html_file, '<table border="1">\n')
write_to_html(
html_file,
'<tr><th>Test</th><th>Iterations</th><th>* Baseline (&#181;s)</th>\
<th>* Benchmark (&#181;s)</th><th>Difference (%)</th></tr>\n'
"<tr><th>Test</th><th>Iterations</th><th>* Baseline (&#181;s)</th>\
<th>* Benchmark (&#181;s)</th><th>Difference (%)</th></tr>\n",
)
total_baseline = total_benchmark = total_diff = total_n_baseline = total_n_benchmark = 0
total_baseline = total_benchmark = total_n_baseline = total_n_benchmark = 0
for test, values in test_results.items():
baseline = values["baseline"] / FONT_COUNT
benchmark = values["benchmark"] / FONT_COUNT
n_baseline = values["n_baseline"] / FONT_COUNT
n_benchmark = values["n_benchmark"] / FONT_COUNT
n_display = f"{n_baseline:.0f} | {n_benchmark:.0f}" if n_baseline != n_benchmark else int(n_baseline)
n_display = (
f"{n_baseline:.0f} | {n_benchmark:.0f}"
if n_baseline != n_benchmark
else int(n_baseline)
)
diff = ((baseline - benchmark) / baseline) * 100 if not (baseline - benchmark) == 0 else 0
diff = (
((baseline - benchmark) / baseline) * 100
if not (baseline - benchmark) == 0
else 0
)
# Calculate for total row
total_baseline += baseline
@ -205,21 +224,15 @@ def generate_total_results_table(html_file, baseline_dir, benchmark_dir):
html_file,
f'<tr><td class="col1">{test}</td><td>{n_display}</td>\
<td class="{baseline_color}">{baseline:.1f}</td>\
<td class="{benchmark_color}">{benchmark:.1f}</td><td>{diff:.1f}</td></tr>\n'
<td class="{benchmark_color}">{benchmark:.1f}</td><td>{diff:.1f}</td></tr>\n',
)
total_diff = ((total_baseline - total_benchmark) / total_baseline) * 100 if not (total_baseline - total_benchmark) == 0 else 0
total_n_display = f"{total_n_baseline} | {total_n_benchmark}" if total_n_baseline != total_n_benchmark else str(total_n_baseline)
write_to_html(
html_file,
f'<tr><td class="col1">Total duration for all tests:</td><td class="col1" colspan="4">{total_time:.0f} s</td>'
f'<tr><td class="col1">Total duration for all tests:</td><td class="col1" colspan="4">{total_time:.0f} s</td>',
)
write_to_html(html_file,'</table>\n')
write_to_html(html_file, "</table>\n")
def generate_results_table(html_file, baseline_results, benchmark_results, filename):
@ -230,23 +243,19 @@ def generate_results_table(html_file, baseline_results, benchmark_results, filen
if line.startswith("ftbench results for font")
][0]
write_to_html(html_file, "<h3>Results for {}</h2>\n".format(fontname))
write_to_html(html_file, f"<h3>Results for {fontname}</h2>\n")
write_to_html(html_file, '<table border="1">\n')
write_to_html(
html_file,
'<tr><th>Test</th><th>Iterations</th>\
<th>* <a href="{}.txt">Baseline</a> (&#181;s)</th>\
<th>* <a href="{}.txt">Benchmark</a> (&#181;s)</th>\
<th>Difference (%)</th></tr>\n'.format(
os.path.join("./baseline/", filename[:-4]),
os.path.join("./benchmark/", filename[:-4]),
),
f'<tr><th>Test</th><th>Iterations</th>\
<th>* <a href="{ os.path.join("./baseline/", filename[:-4])}.txt">Baseline</a> (&#181;s)</th>\
<th>* <a href="{ os.path.join("./benchmark/", filename[:-4])}.txt">Benchmark</a> (&#181;s)</th>\
<th>Difference (%)</th></tr>\n'
)
total_n = total_difference = total_time = 0
total_n = total_time = 0
for baseline_line, benchmark_line in zip(baseline_results, benchmark_results):
if baseline_line.startswith("Total time:"):
baseline_match = re.match(r"Total time: (\d+)s", baseline_line)
benchmark_match = re.match(r"Total time: (\d+)s", benchmark_line)
@ -255,7 +264,6 @@ def generate_results_table(html_file, baseline_results, benchmark_results, filen
total_time += int(baseline_match.group(1))
total_time += int(benchmark_match.group(1))
if baseline_line.startswith(" "):
baseline_match = re.match(
r"\s+(.*?)\s+(\d+\.\d+)\s+microseconds\s+(\d+)\s", baseline_line
@ -269,42 +277,42 @@ def generate_results_table(html_file, baseline_results, benchmark_results, filen
benchmark_value = float(benchmark_match.group(2))
percentage_diff = (
(baseline_value - benchmark_value) / baseline_value
) * 100 if not (baseline_value - benchmark_value) == 0 else 0
((baseline_value - benchmark_value) / baseline_value) * 100
if not (baseline_value - benchmark_value) == 0
else 0
)
baseline_n = baseline_match.group(3)
benchmark_n = benchmark_match.group(3)
n = (
baseline_n
if baseline_n == benchmark_n
else baseline_n + " | " + benchmark_n
)
total_n += int(baseline_n)
total_n += int(benchmark_n)
# Check which value is smaller for color highlighting
baseline_color = "highlight" if baseline_value <= benchmark_value else ""
benchmark_color = "highlight" if benchmark_value <= baseline_value else ""
baseline_color = (
"highlight" if baseline_value <= benchmark_value else ""
)
benchmark_color = (
"highlight" if benchmark_value <= baseline_value else ""
)
write_to_html(
html_file,
f'<tr><td class="col1">{baseline_match.group(1)}</td><td>{n}</td>\
<td class="{baseline_color}">{baseline_value:.1f}</td><td class="{benchmark_color}">{benchmark_value:.1f}</td><td>{percentage_diff:.1f}</td></tr>\n'
<td class="{baseline_color}">{baseline_value:.1f}</td><td class="{benchmark_color}">{benchmark_value:.1f}</td><td>{percentage_diff:.1f}</td></tr>\n',
)
write_to_html(
html_file,
f'<tr><td class="col1">Total duration for the font:</td><td class="col1" colspan="4">{total_time:.0f} s</td></table>\n'
f'<tr><td class="col1">Total duration for the font:</td><td class="col1" colspan="4">{total_time:.0f} s</td></table>\n',
)
if __name__ == "__main__":
main()