1
|
1
|
import os
|
2
|
2
|
import re
|
|
3
|
+import sys
|
3
|
4
|
|
4
|
5
|
# Create the HTML file
|
5
|
|
-current_dir = os.path.dirname(os.path.abspath(__file__))
|
6
|
|
-project_root = os.path.abspath(os.path.join(current_dir, '../../../../'))
|
|
6
|
+project_root = sys.argv[1]
|
7
|
7
|
benchmark_html = os.path.join(project_root, 'benchmark.html')
|
8
|
8
|
|
9
|
9
|
# GitLab URL
|
10
|
10
|
gitlab_url = 'https://gitlab.freedesktop.org/freetype/freetype/-/commit/'
|
11
|
11
|
|
|
12
|
+# CSS style
|
|
13
|
+CSS_STYLE = """
|
|
14
|
+ <style>
|
|
15
|
+ table {
|
|
16
|
+
|
|
17
|
+ }
|
|
18
|
+ th, td {
|
|
19
|
+ padding: 3px;
|
|
20
|
+ text-align: center;
|
|
21
|
+ }
|
|
22
|
+ th {
|
|
23
|
+ background-color: #ccc;
|
|
24
|
+ color: black;
|
|
25
|
+ }
|
|
26
|
+ .warning{
|
|
27
|
+ color: red;
|
|
28
|
+ }
|
|
29
|
+ .col1 {
|
|
30
|
+ background-color: #eee;
|
|
31
|
+ }
|
|
32
|
+
|
|
33
|
+ .highlight {
|
|
34
|
+ background-color: #0a0;
|
|
35
|
+ }
|
|
36
|
+ </style>
|
|
37
|
+"""
|
|
38
|
+
|
12
|
39
|
# Directories
|
13
|
|
-baseline_dir = os.path.join(project_root, 'src/tools/ftbench/baseline')
|
14
|
|
-benchmark_dir = os.path.join(project_root, 'src/tools/ftbench/benchmark')
|
|
40
|
+baseline_dir = os.path.join(project_root, 'baseline')
|
|
41
|
+benchmark_dir = os.path.join(project_root, 'benchmark')
|
15
|
42
|
|
16
|
43
|
# Open HTML file for writing
|
17
|
44
|
with open(benchmark_html, 'w') as html_file:
|
18
|
|
- html_file.write('<html>\n<head>\n<title>Benchmark Results</title>\n</head>\n<body>\n<h1>Benchmark Results</h1>\n')
|
|
45
|
+ html_file.write(f'<html>\n<head>\n<title>Benchmark Results</title>\n{CSS_STYLE}</head>\n<body>\n<h1>Benchmark Results</h1>\n')
|
19
|
46
|
|
20
|
47
|
# If it's the info file, we want to handle it differently
|
21
|
48
|
with open(os.path.join(baseline_dir, "info.txt"), 'r') as f:
|
... |
... |
@@ -25,7 +52,7 @@ with open(benchmark_html, 'w') as html_file: |
25
|
52
|
|
26
|
53
|
# Check if commit ids are the same
|
27
|
54
|
if baseline_info[1].strip() == benchmark_info[1].strip():
|
28
|
|
- html_file.write('<h2 style="color:red;">Warning: Baseline and Benchmark have the same commit ID</h2>\n')
|
|
55
|
+ html_file.write('<h2 class="warning">Warning: Baseline and Benchmark have the same commit ID</h2>\n')
|
29
|
56
|
|
30
|
57
|
baseline_info[1] = '<a href="">{}</a>\n'.format(gitlab_url, baseline_info[1].strip(), baseline_info[1][:8])
|
31
|
58
|
|
... |
... |
@@ -37,10 +64,11 @@ with open(benchmark_html, 'w') as html_file: |
37
|
64
|
html_file.write('<tr><th>Info</th><th>Baseline</th><th>Benchmark</th></tr>\n')
|
38
|
65
|
info_list = ['Parameters', 'Commit ID', 'Commit Date', 'Branch']
|
39
|
66
|
for info, baseline_line, benchmark_line in zip(info_list, baseline_info, benchmark_info):
|
40
|
|
- html_file.write('<tr><td>{}</td><td>{}</td><td>{}</td></tr>\n'.format(info, baseline_line.strip(), benchmark_line.strip()))
|
41
|
|
- html_file.write('</table><br/>\n')
|
42
|
|
-
|
|
67
|
+ html_file.write('<tr><td class="col1">{}</td><td>{}</td><td>{}</td></tr>\n'.format(info, baseline_line.strip(), benchmark_line.strip()))
|
|
68
|
+ html_file.write('</table><br/>')
|
|
69
|
+ html_file.write('*Smaller values mean faster operation<br/>\n')
|
43
|
70
|
# Traverse through the 'baseline' directory
|
|
71
|
+
|
44
|
72
|
for filename in os.listdir(baseline_dir):
|
45
|
73
|
if filename != 'info.txt':
|
46
|
74
|
|
... |
... |
@@ -54,28 +82,29 @@ with open(benchmark_html, 'w') as html_file: |
54
|
82
|
if line.startswith("ftbench results for font"):
|
55
|
83
|
fontname = line.split('/')[-1].strip("'")[:-2]
|
56
|
84
|
|
57
|
|
-
|
|
85
|
+
|
58
|
86
|
# Write results to HTML
|
59
|
87
|
html_file.write('<h2>Results for {}</h2>\n'.format(fontname))
|
60
|
88
|
html_file.write('<table border="1">\n')
|
61
|
|
- html_file.write('<tr><th> Test </th><th> Baseline </th><th> Benchmark </th><th> Difference </th></tr>\n')
|
62
|
|
-
|
|
89
|
+ html_file.write('<tr><th> Test </th><th><a href="">Baseline</a> (µs/op)</th><th> <a href="">Benchmark</a> (µs/op)</th><th> Difference (%)</th></tr>\n'.format(os.path.join(baseline_dir,fontname[:-4]),os.path.join(benchmark_dir,fontname[:-4])))
|
|
90
|
+
|
63
|
91
|
for baseline_line, benchmark_line in zip(baseline_results, benchmark_results):
|
64
|
92
|
if baseline_line.startswith(' '):
|
65
|
|
- baseline_match = re.match(r' (\w+(\s\(\w+\))?)\s+(\d+\.\d+)\s', baseline_line)
|
66
|
|
- benchmark_match = re.match(r' (\w+(\s\(\w+\))?)\s+(\d+\.\d+)\s', benchmark_line)
|
|
93
|
+ baseline_match = re.match(r' (.*\S)\s+(\d+\.\d+)\s', baseline_line)
|
|
94
|
+
|
|
95
|
+ benchmark_match = re.match(r' (.*\S)\s+(\d+\.\d+)\s', benchmark_line)
|
67
|
96
|
|
68
|
97
|
if baseline_match and benchmark_match:
|
69
|
|
- baseline_value = float(baseline_match.group(3))
|
70
|
|
- benchmark_value = float(benchmark_match.group(3))
|
|
98
|
+ baseline_value = float(baseline_match.group(2))
|
|
99
|
+ benchmark_value = float(benchmark_match.group(2))
|
71
|
100
|
|
72
|
101
|
# Calculate the percentage difference
|
73
|
102
|
percentage_diff = ((baseline_value - benchmark_value) / baseline_value) * 100
|
74
|
103
|
|
75
|
104
|
if baseline_value > benchmark_value:
|
76
|
|
- 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))
|
|
105
|
+ 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))
|
77
|
106
|
else:
|
78
|
|
- 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))
|
|
107
|
+ 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))
|
79
|
108
|
|
80
|
109
|
html_file.write('</table><br/>\n')
|
81
|
110
|
|