diff --git a/builds/testing.mk b/builds/testing.mk index c7eb267d9..f2dff8caf 100644 --- a/builds/testing.mk +++ b/builds/testing.mk @@ -5,14 +5,14 @@ FTBENCH_BIN = $(OBJ_DIR)/bench.o FTBENCH_FLAG ?= -c 200 INCLUDES = -I$(TOP_DIR)/include FONTS = $(wildcard $(FTBENCH_DIR)/fonts/*.ttf) -BASELINE = $(addprefix $(FTBENCH_DIR)/baseline/, $(notdir $(FONTS:.ttf=.txt))) -BENCHMARK = $(addprefix $(FTBENCH_DIR)/benchmark/, $(notdir $(FONTS:.ttf=.txt))) -BASELINE_DIR = $(FTBENCH_DIR)/baseline/ -BENCHMARK_DIR = $(FTBENCH_DIR)/benchmark/ +BASELINE_DIR = $(OBJ_DIR)/baseline/ +BENCHMARK_DIR = $(OBJ_DIR)/benchmark/ +BASELINE = $(addprefix $(BASELINE_DIR), $(notdir $(FONTS:.ttf=.txt))) +BENCHMARK = $(addprefix $(BENCHMARK_DIR), $(notdir $(FONTS:.ttf=.txt))) BASELINE_INFO = $(BASELINE_DIR)info.txt BENCHMARK_INFO = $(BENCHMARK_DIR)info.txt HTMLCREATOR = $(FTBENCH_DIR)/src/tohtml.py -HTMLFILE = $(TOP_DIR)/benchmark.html +HTMLFILE = $(OBJ_DIR)/benchmark.html # Create directories for baseline and benchmark $(OBJ_DIR) $(BASELINE_DIR) $(BENCHMARK_DIR): @@ -21,7 +21,7 @@ $(OBJ_DIR) $(BASELINE_DIR) $(BENCHMARK_DIR): # Build ftbench $(FTBENCH_BIN): $(FTBENCH_SRC) | $(OBJ_DIR) @echo "Building ftbench..." - $(CC) $(INCLUDES) $< -lfreetype -o $@ + @$(CC) $(INCLUDES) $< -lfreetype -o $@ # Create a baseline .PHONY: baseline @@ -49,7 +49,7 @@ benchmark: $(FTBENCH_BIN) $(BENCHMARK_DIR) @$(foreach font, $(FONTS), \ $(FTBENCH_BIN) $(FTBENCH_FLAG) $(font) >> $(BENCHMARK_DIR)$(notdir $(font:.ttf=.txt)); \ ) - @$(PYTHON) $(HTMLCREATOR) + @$(PYTHON) $(HTMLCREATOR) $(OBJ_DIR) @echo "Benchmark created." .PHONY: clean-benchmark diff --git a/src/tools/ftbench/src/tohtml.py b/src/tools/ftbench/src/tohtml.py index 3d227bf2b..a3b766654 100644 --- a/src/tools/ftbench/src/tohtml.py +++ b/src/tools/ftbench/src/tohtml.py @@ -1,21 +1,48 @@ import os import re +import sys # Create the HTML file -current_dir = os.path.dirname(os.path.abspath(__file__)) -project_root = os.path.abspath(os.path.join(current_dir, '../../../../')) +project_root = sys.argv[1] benchmark_html = os.path.join(project_root, 'benchmark.html') # GitLab URL gitlab_url = 'https://gitlab.freedesktop.org/freetype/freetype/-/commit/' +# CSS style +CSS_STYLE = """ + +""" + # Directories -baseline_dir = os.path.join(project_root, 'src/tools/ftbench/baseline') -benchmark_dir = os.path.join(project_root, 'src/tools/ftbench/benchmark') +baseline_dir = os.path.join(project_root, 'baseline') +benchmark_dir = os.path.join(project_root, 'benchmark') # Open HTML file for writing with open(benchmark_html, 'w') as html_file: - html_file.write('\n\nBenchmark Results\n\n\n

Benchmark Results

\n') + html_file.write(f'\n\nBenchmark Results\n{CSS_STYLE}\n\n

Benchmark Results

\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: @@ -25,7 +52,7 @@ with open(benchmark_html, 'w') as html_file: # Check if commit ids are the same if baseline_info[1].strip() == benchmark_info[1].strip(): - html_file.write('

Warning: Baseline and Benchmark have the same commit ID

\n') + html_file.write('

Warning: Baseline and Benchmark have the same commit ID

\n') baseline_info[1] = '{}\n'.format(gitlab_url, baseline_info[1].strip(), baseline_info[1][:8]) @@ -37,10 +64,11 @@ with open(benchmark_html, 'w') as html_file: html_file.write('InfoBaselineBenchmark\n') info_list = ['Parameters', 'Commit ID', 'Commit Date', 'Branch'] for info, baseline_line, benchmark_line in zip(info_list, baseline_info, benchmark_info): - html_file.write('{}{}{}\n'.format(info, baseline_line.strip(), benchmark_line.strip())) - html_file.write('
\n') - + html_file.write('{}{}{}\n'.format(info, baseline_line.strip(), benchmark_line.strip())) + html_file.write('
') + html_file.write('*Smaller values mean faster operation
\n') # Traverse through the 'baseline' directory + for filename in os.listdir(baseline_dir): if filename != 'info.txt': @@ -54,28 +82,29 @@ with open(benchmark_html, 'w') as html_file: if line.startswith("ftbench results for font"): fontname = line.split('/')[-1].strip("'")[:-2] - + # Write results to HTML html_file.write('

Results for {}

\n'.format(fontname)) html_file.write('\n') - html_file.write('\n') - + html_file.write('\n'.format(os.path.join(baseline_dir,fontname[:-4]),os.path.join(benchmark_dir,fontname[:-4]))) + for baseline_line, benchmark_line in zip(baseline_results, benchmark_results): if baseline_line.startswith(' '): - baseline_match = re.match(r' (\w+(\s\(\w+\))?)\s+(\d+\.\d+)\s', baseline_line) - benchmark_match = re.match(r' (\w+(\s\(\w+\))?)\s+(\d+\.\d+)\s', benchmark_line) + baseline_match = re.match(r' (.*\S)\s+(\d+\.\d+)\s', baseline_line) + + benchmark_match = re.match(r' (.*\S)\s+(\d+\.\d+)\s', benchmark_line) if baseline_match and benchmark_match: - baseline_value = float(baseline_match.group(3)) - benchmark_value = float(benchmark_match.group(3)) + baseline_value = float(baseline_match.group(2)) + benchmark_value = float(benchmark_match.group(2)) # Calculate the percentage difference percentage_diff = ((baseline_value - benchmark_value) / baseline_value) * 100 if baseline_value > benchmark_value: - html_file.write('\n'.format(baseline_match.group(1), baseline_value, benchmark_value, percentage_diff)) + html_file.write('\n'.format(baseline_match.group(1), baseline_value, benchmark_value, percentage_diff)) else: - html_file.write('\n'.format(baseline_match.group(1), baseline_value, benchmark_value, percentage_diff)) + html_file.write('\n'.format(baseline_match.group(1), baseline_value, benchmark_value, percentage_diff)) html_file.write('
Test Baseline Benchmark Difference
Test Baseline (µs/op) Benchmark (µs/op) Difference (%)
{}{:.2f}\tus/op{:.2f}\tus/op{:.2f}%
{}{:.2f}{:.2f}{:.2f}
{}{:.2f}\tus/op{:.2f}\tus/op{:.2f}%
{}{:.2f}{:.2f}{:.2f}

\n')