SOLID python and bug fixes for others
This commit is contained in:
parent
f9775cf1ee
commit
5025ea6e49
|
@ -3,7 +3,7 @@ FTBENCH_DIR = $(TOP_DIR)/src/tools/ftbench
|
||||||
FTBENCH_SRC = $(FTBENCH_DIR)/ftbench.c
|
FTBENCH_SRC = $(FTBENCH_DIR)/ftbench.c
|
||||||
FTBENCH_OBJ = $(OBJ_DIR)/bench.$(SO)
|
FTBENCH_OBJ = $(OBJ_DIR)/bench.$(SO)
|
||||||
FTBENCH_BIN = $(OBJ_DIR)/bench$E
|
FTBENCH_BIN = $(OBJ_DIR)/bench$E
|
||||||
FTBENCH_FLAG ?= -c 2000
|
FTBENCH_FLAG ?= -c 500
|
||||||
INCLUDES = $(TOP_DIR)/include
|
INCLUDES = $(TOP_DIR)/include
|
||||||
FONTS = $(wildcard $(FTBENCH_DIR)/fonts/*.ttf)
|
FONTS = $(wildcard $(FTBENCH_DIR)/fonts/*.ttf)
|
||||||
BASELINE_DIR = $(OBJ_DIR)/baseline/
|
BASELINE_DIR = $(OBJ_DIR)/baseline/
|
||||||
|
@ -73,13 +73,13 @@ $(BASELINE_DIR) $(BENCHMARK_DIR):
|
||||||
@mkdir -p $@
|
@mkdir -p $@
|
||||||
|
|
||||||
$(FTBENCH_OBJ): $(FTBENCH_SRC)
|
$(FTBENCH_OBJ): $(FTBENCH_SRC)
|
||||||
$(COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<) $(EXTRAFLAGS)
|
@$(COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<) $(EXTRAFLAGS)
|
||||||
@echo "Object created."
|
@echo "Object created."
|
||||||
|
|
||||||
# Build ftbench
|
# Build ftbench
|
||||||
$(FTBENCH_BIN): $(FTBENCH_OBJ)
|
$(FTBENCH_BIN): $(FTBENCH_OBJ)
|
||||||
@echo "Linking ftbench..."
|
@echo "Linking ftbench..."
|
||||||
$(LINK_CMD) $T$(subst /,$(COMPILER_SEP),$@ $<) $(LINK_LIBS)
|
@$(LINK_CMD) $T$(subst /,$(COMPILER_SEP),$@ $<) $(LINK_LIBS)
|
||||||
@echo "Built."
|
@echo "Built."
|
||||||
|
|
||||||
# Create a baseline
|
# Create a baseline
|
||||||
|
|
|
@ -300,7 +300,7 @@
|
||||||
|
|
||||||
if ( done )
|
if ( done )
|
||||||
printf( "%10.3f ms %10d done\n",
|
printf( "%10.3f ms %10d done\n",
|
||||||
TIMER_GET( &timer ) / 1000, done );
|
TIMER_GET( &timer ) / 1000000, done );
|
||||||
else
|
else
|
||||||
printf( "no error-free calls\n" );
|
printf( "no error-free calls\n" );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
"""This module converts the benchmark results into a HTML file."""
|
"""This script generates a HTML file from the results of ftbench"""
|
||||||
|
# Ahmet Goksu ahmet@goksu.in ahmet.goksu.in
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# Create the HTML file
|
|
||||||
PROJECT_ROOT = sys.argv[1]
|
PROJECT_ROOT = sys.argv[1]
|
||||||
BENCHMARK_HTML = os.path.join(PROJECT_ROOT, "benchmark.html")
|
BENCHMARK_HTML = os.path.join(PROJECT_ROOT, "benchmark.html")
|
||||||
|
|
||||||
# GitLab URL
|
|
||||||
GITLAB_URL = "https://gitlab.freedesktop.org/freetype/freetype/-/commit/"
|
GITLAB_URL = "https://gitlab.freedesktop.org/freetype/freetype/-/commit/"
|
||||||
|
|
||||||
# CSS style
|
|
||||||
CSS_STYLE = """
|
CSS_STYLE = """
|
||||||
<style>
|
<style>
|
||||||
table {
|
table {
|
||||||
|
@ -36,157 +33,166 @@ CSS_STYLE = """
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Directories
|
|
||||||
BASELINE_DIR = os.path.join(PROJECT_ROOT, "baseline")
|
BASELINE_DIR = os.path.join(PROJECT_ROOT, "baseline")
|
||||||
BENCHMARK_DIR = os.path.join(PROJECT_ROOT, "benchmark")
|
BENCHMARK_DIR = os.path.join(PROJECT_ROOT, "benchmark")
|
||||||
|
|
||||||
# Open HTML file for writing and write the header
|
def main():
|
||||||
with open(BENCHMARK_HTML, "w") as html_file:
|
"""Entry point for the script"""
|
||||||
html_file.write(
|
with open(BENCHMARK_HTML, "w") as html_file:
|
||||||
f"<html>\n\
|
write_to_html(html_file, "<html>\n<head>\n")
|
||||||
<head>\n\
|
write_to_html(html_file, CSS_STYLE)
|
||||||
<title>Benchmark Results</title>\n\
|
write_to_html(html_file, "</head>\n<body>\n")
|
||||||
{CSS_STYLE}\
|
|
||||||
</head>\n\
|
baseline_info = parse_info_file(os.path.join(BASELINE_DIR, "info.txt"))
|
||||||
<body>\n\
|
benchmark_info = parse_info_file(os.path.join(BENCHMARK_DIR, "info.txt"))
|
||||||
<h1>Benchmark Results</h1>\n"
|
|
||||||
|
if baseline_info[1].strip() == benchmark_info[1].strip():
|
||||||
|
write_to_html(
|
||||||
|
html_file,
|
||||||
|
'<h2 class="warning">Warning: Baseline and Benchmark have the same commit ID</h2>\n',
|
||||||
|
)
|
||||||
|
|
||||||
|
generate_info_table(html_file, baseline_info, benchmark_info)
|
||||||
|
|
||||||
|
# Generate results tables
|
||||||
|
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))
|
||||||
|
|
||||||
|
generate_results_table(
|
||||||
|
html_file, baseline_results, benchmark_results, filename
|
||||||
|
)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
def read_file(file_path):
|
||||||
|
"""Read file and return list of lines"""
|
||||||
|
with open(file_path, "r") as f:
|
||||||
|
return f.readlines()
|
||||||
|
|
||||||
|
|
||||||
|
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])
|
||||||
|
return info
|
||||||
|
|
||||||
|
|
||||||
|
def generate_info_table(html_file, baseline_info, benchmark_info):
|
||||||
|
"""Prepare info table for html"""
|
||||||
|
write_to_html(html_file, "<h2>Info</h2>\n")
|
||||||
|
write_to_html(html_file, '<table border="1">\n')
|
||||||
|
write_to_html(
|
||||||
|
html_file, "<tr><th>Info</th><th>Baseline</th><th>Benchmark</th></tr>\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
# If it's the info file, we want to handle it differently
|
|
||||||
with open(os.path.join(BASELINE_DIR, "info.txt"), "r") as f:
|
|
||||||
baseline_info = f.readlines()
|
|
||||||
with open(os.path.join(BENCHMARK_DIR, "info.txt"), "r") as f:
|
|
||||||
benchmark_info = f.readlines()
|
|
||||||
|
|
||||||
# Check if commit ids are the same
|
|
||||||
if baseline_info[1].strip() == benchmark_info[1].strip():
|
|
||||||
html_file.write(
|
|
||||||
'<h2 class="warning">Warning: Baseline and Benchmark have the same commit ID</h2>\n'
|
|
||||||
)
|
|
||||||
|
|
||||||
baseline_info[1] = '<a href="{}{}">{}</a>\n'.format(
|
|
||||||
GITLAB_URL, baseline_info[1].strip(), baseline_info[1][:8]
|
|
||||||
)
|
|
||||||
|
|
||||||
benchmark_info[1] = '<a href="{}{}">{}</a>\n'.format(
|
|
||||||
GITLAB_URL, benchmark_info[1].strip(), benchmark_info[1][:8]
|
|
||||||
)
|
|
||||||
|
|
||||||
# Write info table
|
|
||||||
html_file.write("<h2>Info</h2>\n")
|
|
||||||
html_file.write('<table border="1">\n')
|
|
||||||
html_file.write("<tr><th>Info</th><th>Baseline</th><th>Benchmark</th></tr>\n")
|
|
||||||
info_list = ["Parameters", "Commit ID", "Commit Date", "Branch"]
|
info_list = ["Parameters", "Commit ID", "Commit Date", "Branch"]
|
||||||
for info, baseline_line, benchmark_line in zip(
|
for info, baseline_line, benchmark_line in zip(
|
||||||
info_list, baseline_info, benchmark_info
|
info_list, baseline_info, benchmark_info
|
||||||
):
|
):
|
||||||
html_file.write(
|
write_to_html(
|
||||||
|
html_file,
|
||||||
'<tr><td class="col1">{}</td><td>{}</td><td>{}</td></tr>\n'.format(
|
'<tr><td class="col1">{}</td><td>{}</td><td>{}</td></tr>\n'.format(
|
||||||
info, baseline_line.strip(), benchmark_line.strip()
|
info, baseline_line.strip(), benchmark_line.strip()
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
html_file.write("</table><br/>")
|
write_to_html(html_file, "</table><br/>")
|
||||||
html_file.write("*Smaller values mean faster operation<br/>\n")
|
write_to_html(html_file, "*Smaller values mean faster operation<br/>\n")
|
||||||
# Traverse through the 'baseline' directory
|
|
||||||
for filename in os.listdir(BASELINE_DIR):
|
|
||||||
if filename != "info.txt":
|
|
||||||
with open(os.path.join(BASELINE_DIR, filename), "r") as f:
|
|
||||||
baseline_results = f.readlines()
|
|
||||||
with open(os.path.join(BENCHMARK_DIR, filename), "r") as f:
|
|
||||||
benchmark_results = f.readlines()
|
|
||||||
|
|
||||||
# Get font name from within the .txt file
|
|
||||||
for line in baseline_results:
|
|
||||||
if line.startswith("ftbench results for font"):
|
|
||||||
fontname = line.split("/")[-1]\
|
|
||||||
.strip("'")[:-2]
|
|
||||||
|
|
||||||
# Write test column headers
|
def generate_results_table(html_file, baseline_results, benchmark_results, filename):
|
||||||
html_file.write("<h2>Results for {}</h2>\n".format(fontname))
|
"""Prepare results table for html"""
|
||||||
html_file.write('<table border="1">\n')
|
fontname = [
|
||||||
html_file.write(
|
line.split("/")[-1].strip("'")[:-2]
|
||||||
'<tr>\
|
for line in baseline_results
|
||||||
<th>Test</th>\
|
if line.startswith("ftbench results for font")
|
||||||
<th>N</th>\
|
][0]
|
||||||
<th><a href="{}.txt">Baseline</a> (ms)</th>\
|
|
||||||
<th><a href="{}.txt">Benchmark</a> (ms)</th>\
|
write_to_html(html_file, "<h2>Results for {}</h2>\n".format(fontname))
|
||||||
<th>Difference (%)</th>\
|
write_to_html(html_file, '<table border="1">\n')
|
||||||
</tr>\n'.format(
|
write_to_html(
|
||||||
os.path.join(BASELINE_DIR, fontname[:-4]),
|
html_file,
|
||||||
os.path.join(BENCHMARK_DIR, fontname[:-4]),
|
'<tr><th>Test</th><th>N</th>\
|
||||||
)
|
<th><a href="{}.txt">Baseline</a> (ms)</th>\
|
||||||
|
<th><a href="{}.txt">Benchmark</a> (ms)</th>\
|
||||||
|
<th>Difference (%)</th></tr>\n'.format(
|
||||||
|
os.path.join(BASELINE_DIR, filename[:-4]),
|
||||||
|
os.path.join(BENCHMARK_DIR, filename[:-4]),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
total_n = total_time_baseline = total_time_benchmark = total_difference = 0
|
||||||
|
|
||||||
|
for baseline_line, benchmark_line in zip(baseline_results, benchmark_results):
|
||||||
|
if baseline_line.startswith(" "):
|
||||||
|
baseline_match = re.match(
|
||||||
|
r"\s+(.*?)\s+(\d+\.\d+)\s+ms\s+(\d+)\s", baseline_line
|
||||||
|
)
|
||||||
|
benchmark_match = re.match(
|
||||||
|
r"\s+(.*?)\s+(\d+\.\d+)\s+ms\s+(\d+)\s", benchmark_line
|
||||||
)
|
)
|
||||||
|
|
||||||
# Write test results
|
if baseline_match and benchmark_match:
|
||||||
for baseline_line, benchmark_line in zip(
|
baseline_value = float(baseline_match.group(2))
|
||||||
baseline_results, benchmark_results
|
benchmark_value = float(benchmark_match.group(2))
|
||||||
):
|
|
||||||
# Check if line is a test result
|
percentage_diff = (
|
||||||
# Get results by Regex
|
(baseline_value - benchmark_value) / baseline_value
|
||||||
if baseline_line.startswith(" "):
|
) * 100
|
||||||
baseline_match = re.match(
|
|
||||||
r"\s+(.*?)\s+(\d+\.\d+)\s+ms\s+(\d+)\s", baseline_line
|
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)
|
||||||
|
total_time_baseline += baseline_value
|
||||||
|
total_time_benchmark += benchmark_value
|
||||||
|
total_difference += percentage_diff
|
||||||
|
|
||||||
|
if baseline_value > benchmark_value:
|
||||||
|
write_to_html(
|
||||||
|
html_file,
|
||||||
|
'<tr><td class="col1">{}</td><td>{}</td>\
|
||||||
|
<td class="lowlight">{:.3f}</td><td class="highlight">{:.3f}</td><td>{:.1f}</td></tr>\n'.format(
|
||||||
|
baseline_match.group(1),
|
||||||
|
n,
|
||||||
|
baseline_value,
|
||||||
|
benchmark_value,
|
||||||
|
percentage_diff,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
write_to_html(
|
||||||
|
html_file,
|
||||||
|
'<tr><td class="col1">{}</td><td>{}</td>\
|
||||||
|
<td class="highlight">{:.3f}</td><td class="lowlight">{:.3f}</td><td>{:.1f}</td></tr>\n'.format(
|
||||||
|
baseline_match.group(1),
|
||||||
|
n,
|
||||||
|
baseline_value,
|
||||||
|
benchmark_value,
|
||||||
|
percentage_diff,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
benchmark_match = re.match(
|
write_to_html(
|
||||||
r"\s+(.*?)\s+(\d+\.\d+)\s+ms\s+(\d+)\s", benchmark_line
|
html_file,
|
||||||
)
|
'<tr><td class="col1">TOTAL</td><td class="col1">{}</td>\
|
||||||
|
<td class="col1">{:.3f}</td><td class="col1">{:.3f}</td><td class="col1">{:.1f}</td></tr>\n'.format(
|
||||||
|
total_n, total_time_baseline, total_time_benchmark, total_difference / 14
|
||||||
|
),
|
||||||
|
)
|
||||||
|
write_to_html(html_file, "</table><br/>\n")
|
||||||
|
|
||||||
if baseline_match and benchmark_match:
|
if __name__ == "__main__":
|
||||||
baseline_value = float(baseline_match.group(2))
|
main()
|
||||||
benchmark_value = float(benchmark_match.group(2))
|
|
||||||
|
|
||||||
# Calculate the percentage difference
|
|
||||||
percentage_diff = (
|
|
||||||
(baseline_value - benchmark_value) / baseline_value
|
|
||||||
) * 100
|
|
||||||
|
|
||||||
# Get itaration number
|
|
||||||
baseline_n = baseline_match.group(3)
|
|
||||||
benchmark_n = benchmark_match.group(3)
|
|
||||||
|
|
||||||
# Check if iteration number is the same
|
|
||||||
if baseline_n == benchmark_n:
|
|
||||||
total_n = baseline_n
|
|
||||||
else:
|
|
||||||
total_n = baseline_n +\
|
|
||||||
" / " + benchmark_n
|
|
||||||
|
|
||||||
# Highlight the faster value
|
|
||||||
if baseline_value > benchmark_value:
|
|
||||||
html_file.write(
|
|
||||||
'<tr>\
|
|
||||||
<td class="col1">{}</td>\
|
|
||||||
<td>{}</td>\
|
|
||||||
<td class="lowlight">{:.3f}</td>\
|
|
||||||
<td class="highlight">{:.3f}</td>\
|
|
||||||
<td>{:.1f}</td>\
|
|
||||||
</tr>\n'.format(
|
|
||||||
baseline_match.group(1),
|
|
||||||
total_n,
|
|
||||||
baseline_value,
|
|
||||||
benchmark_value,
|
|
||||||
percentage_diff,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
html_file.write(
|
|
||||||
'<tr>\
|
|
||||||
<td class="col1">{}</td>\
|
|
||||||
<td>{}</td>\
|
|
||||||
<td class="highlight">{:.3f}</td>\
|
|
||||||
<td class="lowlight">{:.3f}</td>\
|
|
||||||
<td>{:.1f}</td>\
|
|
||||||
</tr>\n'.format(
|
|
||||||
baseline_match.group(1),
|
|
||||||
total_n,
|
|
||||||
baseline_value,
|
|
||||||
benchmark_value,
|
|
||||||
percentage_diff,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
html_file.write("</table><br/>\n")
|
|
||||||
|
|
||||||
html_file.write("<center>Freetype Benchmark</center></body>\n</html>\n")
|
|
||||||
|
|
Loading…
Reference in New Issue