freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2] GSoC-2023-Ahmet f95a2c827 4/4: make integrated


From: Werner Lemberg
Subject: [freetype2] GSoC-2023-Ahmet f95a2c827 4/4: make integrated
Date: Mon, 12 Jun 2023 10:45:39 -0400 (EDT)

branch: GSoC-2023-Ahmet
commit f95a2c82799777f0ec5af227a88a61c007ca08ea
Author: goksu <25721443+goeksu@users.noreply.github.com>
Commit: goksu <25721443+goeksu@users.noreply.github.com>

    make integrated
---
 builds/freetype.mk                                 |   5 ++
 builds/testing.mk                                  |  46 ++++++++++++++++++
 src/tools/ftbench/Makefile                         |  40 ----------------
 .../fonts/{ => deactivated}/Arial_subset.ttf       | Bin
 .../fonts/{ => deactivated}/Roboto_subset.ttf      | Bin
 .../fonts/{ => deactivated}/Tahoma_subset.ttf      | Bin
 .../{ => deactivated}/TimesNewRoman_subset.ttf     | Bin
 src/tools/ftbench/fonts/sub.sh                     |  15 ------
 src/tools/ftbench/ftbench.c                        |   2 +-
 src/tools/ftbench/src/benchmark.html               |   6 +++
 src/tools/ftbench/{ => src}/mlgetopt.h             |   0
 src/tools/ftbench/src/tohtml.py                    |  53 +++++++++++++++++++++
 12 files changed, 111 insertions(+), 56 deletions(-)

diff --git a/builds/freetype.mk b/builds/freetype.mk
index d96ded072..32a3659e1 100644
--- a/builds/freetype.mk
+++ b/builds/freetype.mk
@@ -162,6 +162,11 @@ FT_COMPILE := $(CC) $(ANSIFLAGS) $(INCLUDE_FLAGS) 
$(FT_CFLAGS)
 include $(TOP_DIR)/builds/exports.mk
 
 
+# Include the `testing' rules file.
+#
+include $(TOP_DIR)/builds/testing.mk
+
+
 # Initialize the list of objects.
 #
 OBJECTS_LIST :=
diff --git a/builds/testing.mk b/builds/testing.mk
new file mode 100644
index 000000000..cf16f2daf
--- /dev/null
+++ b/builds/testing.mk
@@ -0,0 +1,46 @@
+# Variables
+FTBENCH_DIR = $(TOP_DIR)/src/tools/ftbench
+FTBENCH_SRC = $(FTBENCH_DIR)/ftbench.c
+FTBENCH_BIN = $(FTBENCH_DIR)/bench
+FTBENCH_FLAGS = $(shell pkg-config --cflags freetype2) -lfreetype
+FONTS = $(wildcard $(FTBENCH_DIR)/fonts/*.ttf)
+BASELINES = $(addprefix $(FTBENCH_DIR)/baselines/, $(notdir 
$(FONTS:.ttf=.txt)))
+BENCHMARKS = $(addprefix $(FTBENCH_DIR)/benchmarks/, $(notdir 
$(FONTS:.ttf=.txt)))
+PYTHON = python3
+HTMLCREATOR = $(FTBENCH_DIR)/src/tohtml.py
+HTMLFILE = $(TOP_DIR)/benchmark.html
+
+# Create directories for baselines and benchmarks
+$(FTBENCH_DIR)/baselines/ $(FTBENCH_DIR)/benchmarks/:
+       @mkdir -p $@
+
+# Build ftbench
+$(FTBENCH_BIN): $(FTBENCH_SRC)
+       @echo "Building ftbench..."
+       @gcc $(FTBENCH_FLAGS) $< -o $@
+
+# Create a baseline
+.PHONY: baseline
+baseline: $(FTBENCH_BIN) $(FTBENCH_DIR)/baselines/
+       @echo "Creating baseline..."
+       @$(foreach font, $(FONTS), \
+               $(FTBENCH_BIN) $(font) > $(FTBENCH_DIR)/baselines/$(notdir 
$(font:.ttf=.txt)); \
+       )
+       @echo "Baseline created."
+
+# Benchmark and compare to baseline
+.PHONY: benchmark
+benchmark: $(FTBENCH_BIN) $(FTBENCH_DIR)/benchmarks/
+       @echo "Creating benchmark..."
+       @$(foreach font, $(FONTS), \
+               $(FTBENCH_BIN) $(font) > $(FTBENCH_DIR)/benchmarks/$(notdir 
$(font:.ttf=.txt)); \
+       )
+       @$(PYTHON) $(HTMLCREATOR) > $(HTMLFILE)
+       @echo "Benchmark created."
+
+.PHONY: clean-benchmark
+clean-benchmark:
+       @echo "Cleaning..."
+       @rm -f $(FTBENCH_BIN)
+       @rm -rf $(FTBENCH_DIR)/baselines/ $(FTBENCH_DIR)/benchmarks/ $(HTMLFILE)
+       @echo "Cleaned."
diff --git a/src/tools/ftbench/Makefile b/src/tools/ftbench/Makefile
deleted file mode 100644
index a8211ebd5..000000000
--- a/src/tools/ftbench/Makefile
+++ /dev/null
@@ -1,40 +0,0 @@
-# Variables
-FTBENCH_SRC = ftbench.c
-FTBENCH_BIN = bench.out
-FTBENCH_FLAGS = $(shell pkg-config --cflags freetype2) -lfreetype
-FONTS = $(wildcard fonts/*.ttf)
-BASELINES = $(addprefix baselines/, $(notdir $(FONTS)))
-BENCHMARKS = $(addprefix benchmarks/, $(notdir $(FONTS)))
-
-# Default target
-all: $(FTBENCH_BIN)
-
-# Build ftbench
-$(FTBENCH_BIN): $(FTBENCH_SRC)
-       gcc $(FTBENCH_FLAGS) $(FTBENCH_SRC) -o $(FTBENCH_BIN)
-
-# Create directories for baselines and benchmarks
-baselines/ benchmarks/:
-       mkdir -p $@
-
-# Create a baseline
-.PHONY: baseline
-baseline: $(FTBENCH_BIN) baselines/
-       $(foreach font, $(FONTS), \
-               ./$(FTBENCH_BIN) $(font) > baselines/$(notdir $(font)).txt; \
-       )
-
-# Benchmark and compare to baseline
-.PHONY: benchmark
-benchmark: $(FTBENCH_BIN) benchmarks/
-       $(foreach font, $(FONTS), \
-               ./$(FTBENCH_BIN) $(font) > benchmarks/$(notdir $(font)).txt; \
-       )
-       $(foreach font, $(FONTS), \
-               diff baselines/$(notdir $(font)).txt benchmarks/$(notdir 
$(font)).txt; \
-       )
-
-.PHONY: clean
-clean:
-       rm -f $(FTBENCH_BIN)
-       rm -rf baselines/ benchmarks/
diff --git a/src/tools/ftbench/fonts/Arial_subset.ttf 
b/src/tools/ftbench/fonts/deactivated/Arial_subset.ttf
similarity index 100%
rename from src/tools/ftbench/fonts/Arial_subset.ttf
rename to src/tools/ftbench/fonts/deactivated/Arial_subset.ttf
diff --git a/src/tools/ftbench/fonts/Roboto_subset.ttf 
b/src/tools/ftbench/fonts/deactivated/Roboto_subset.ttf
similarity index 100%
rename from src/tools/ftbench/fonts/Roboto_subset.ttf
rename to src/tools/ftbench/fonts/deactivated/Roboto_subset.ttf
diff --git a/src/tools/ftbench/fonts/Tahoma_subset.ttf 
b/src/tools/ftbench/fonts/deactivated/Tahoma_subset.ttf
similarity index 100%
rename from src/tools/ftbench/fonts/Tahoma_subset.ttf
rename to src/tools/ftbench/fonts/deactivated/Tahoma_subset.ttf
diff --git a/src/tools/ftbench/fonts/TimesNewRoman_subset.ttf 
b/src/tools/ftbench/fonts/deactivated/TimesNewRoman_subset.ttf
similarity index 100%
rename from src/tools/ftbench/fonts/TimesNewRoman_subset.ttf
rename to src/tools/ftbench/fonts/deactivated/TimesNewRoman_subset.ttf
diff --git a/src/tools/ftbench/fonts/sub.sh b/src/tools/ftbench/fonts/sub.sh
deleted file mode 100644
index 3b114cce8..000000000
--- a/src/tools/ftbench/fonts/sub.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/bash
-
-# Define the Unicode range
-unicodes="U+0021-007E"
-
-# Loop over all .ttf files in the current directory
-for fontfile in *.ttf
-do
-  # Generate the output filename
-  output="${fontfile%.ttf}_subset.ttf"
-
-  # Run the pyftsubset command
-  pyftsubset "$fontfile" --unicodes=$unicodes --output-file="$output"
-done
-
diff --git a/src/tools/ftbench/ftbench.c b/src/tools/ftbench/ftbench.c
index 2f0f2a4e6..13cfd9b0d 100644
--- a/src/tools/ftbench/ftbench.c
+++ b/src/tools/ftbench/ftbench.c
@@ -40,7 +40,7 @@
 #ifdef UNIX
 #include <unistd.h>
 #else
-#include "mlgetopt.h"
+#include "src/mlgetopt.h"
 #endif
 
 #ifdef _WIN32
diff --git a/src/tools/ftbench/src/benchmark.html 
b/src/tools/ftbench/src/benchmark.html
new file mode 100644
index 000000000..b4cba9c9e
--- /dev/null
+++ b/src/tools/ftbench/src/benchmark.html
@@ -0,0 +1,6 @@
+<html>
+<head>
+<title>Benchmark Results</title>
+</head>
+<body>
+<h1>Benchmark Results</h1>
diff --git a/src/tools/ftbench/mlgetopt.h b/src/tools/ftbench/src/mlgetopt.h
similarity index 100%
rename from src/tools/ftbench/mlgetopt.h
rename to src/tools/ftbench/src/mlgetopt.h
diff --git a/src/tools/ftbench/src/tohtml.py b/src/tools/ftbench/src/tohtml.py
new file mode 100644
index 000000000..c5b912e7b
--- /dev/null
+++ b/src/tools/ftbench/src/tohtml.py
@@ -0,0 +1,53 @@
+import os
+import re
+
+# Create the HTML file
+with open('../../../../benchmark.html', 'w') as f:
+    f.write('<html>\n')
+    f.write('<head>\n')
+    f.write('<title>Benchmark Results</title>\n')
+    f.write('</head>\n')
+    f.write('<body>\n')
+    f.write('<h1>Benchmark Results</h1>\n')
+
+    # Traverse through the 'baselines' directory
+    for filename in os.listdir('../baselines'):
+        baseline_filepath = os.path.join('../baselines', filename)
+        benchmark_filepath = os.path.join('../benchmarks', filename)
+
+        # Process the baseline file
+        with open(baseline_filepath, 'r') as baseline_file:
+            baseline_lines = baseline_file.readlines()
+
+        # Process the benchmark file
+        with open(benchmark_filepath, 'r') as benchmark_file:
+            benchmark_lines = benchmark_file.readlines()
+
+        f.write(f'<h2>Results for {filename}</h2>\n')
+        f.write('<table border="1">\n')
+        f.write('<tr><th>Test</th><th>Baseline</th><th>Benchmark</th></tr>\n')
+
+        # For each line in the baseline and benchmark files
+        for baseline_line, benchmark_line in zip(baseline_lines, 
benchmark_lines):
+            # If the line starts with a space, it's a test result line
+            if baseline_line.startswith('  '):
+                # Extract the test name, the time per operation, and the 
number of operations done
+                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)
+
+                # If the line could be parsed
+                if baseline_match and benchmark_match:
+                    # Check which value is higher
+                    baseline_value = float(baseline_match.group(3))
+                    benchmark_value = float(benchmark_match.group(3))
+
+                    # Write the test result to the HTML file
+                    if baseline_value > benchmark_value:
+                        f.write(f'<tr><td>{baseline_match.group(1)}</td><td 
style="background-color: 
green;">{baseline_match.group(3)}</td><td>{benchmark_match.group(3)}</td></tr>\n')
+                    else:
+                        
f.write(f'<tr><td>{baseline_match.group(1)}</td><td>{baseline_match.group(3)}</td><td
 style="background-color: green;">{benchmark_match.group(3)}</td></tr>\n')
+
+        f.write('</table>\n')
+
+    f.write('</body>\n')
+    f.write('</html>\n')



reply via email to

[Prev in Thread] Current Thread [Next in Thread]