GSoC-2023-Ahmet
goksu 2 years ago
parent 1afa5619ba
commit ceb8fab9ae
No known key found for this signature in database
  1. 14
      builds/testing.mk
  2. 65
      src/tools/ftbench/src/tohtml.py

@ -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

@ -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 = """
<style>
table {
}
th, td {
padding: 3px;
text-align: center;
}
th {
background-color: #ccc;
color: black;
}
.warning{
color: red;
}
.col1 {
background-color: #eee;
}
.highlight {
background-color: #0a0;
}
</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('<html>\n<head>\n<title>Benchmark Results</title>\n</head>\n<body>\n<h1>Benchmark Results</h1>\n')
html_file.write(f'<html>\n<head>\n<title>Benchmark Results</title>\n{CSS_STYLE}</head>\n<body>\n<h1>Benchmark Results</h1>\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('<h2 style="color:red;">Warning: Baseline and Benchmark have the same commit ID</h2>\n')
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])
@ -37,10 +64,11 @@ with open(benchmark_html, 'w') as html_file:
html_file.write('<tr><th>Info</th><th>Baseline</th><th>Benchmark</th></tr>\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('<tr><td>{}</td><td>{}</td><td>{}</td></tr>\n'.format(info, baseline_line.strip(), benchmark_line.strip()))
html_file.write('</table><br/>\n')
html_file.write('<tr><td class="col1">{}</td><td>{}</td><td>{}</td></tr>\n'.format(info, baseline_line.strip(), benchmark_line.strip()))
html_file.write('</table><br/>')
html_file.write('*Smaller values mean faster operation<br/>\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('<h2>Results for {}</h2>\n'.format(fontname))
html_file.write('<table border="1">\n')
html_file.write('<tr><th> Test </th><th> Baseline </th><th> Benchmark </th><th> Difference </th></tr>\n')
html_file.write('<tr><th> Test </th><th><a href="{}.txt">Baseline</a> (&#181;s/op)</th><th> <a href="{}.txt">Benchmark</a> (&#181;s/op)</th><th> Difference (%)</th></tr>\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('<tr><td>{}</td><td>{:.2f}\tus/op</td><td style="background-color: green;">{:.2f}\tus/op</td><td>{:.2f}%</td></tr>\n'.format(baseline_match.group(1), baseline_value, benchmark_value, percentage_diff))
html_file.write('<tr><td class="col1">{}</td><td class="lowlight">{:.2f}</td><td class="highlight">{:.2f}</td><td>{:.2f}</td></tr>\n'.format(baseline_match.group(1), baseline_value, benchmark_value, percentage_diff))
else:
html_file.write('<tr><td>{}</td><td>{:.2f}\tus/op</td><td>{:.2f}\tus/op</td><td>{:.2f}%</td></tr>\n'.format(baseline_match.group(1), baseline_value, benchmark_value, percentage_diff))
html_file.write('<tr><td class="col1">{}</td><td class="highlight">{:.2f}</td><td class="lowlight">{:.2f}</td><td>{:.2f}</td></tr>\n'.format(baseline_match.group(1), baseline_value, benchmark_value, percentage_diff))
html_file.write('</table><br/>\n')

Loading…
Cancel
Save