Ahmet Göksu pushed to branch GSoC-2023-Ahmet at FreeType / FreeType
Commits:
-
a6c2517e
by goksu at 2023-09-18T09:32:17+03:00
4 changed files:
- builds/testing.mk
- + src/tools/ftbench/README
- src/tools/ftbench/fonts/tool/sub.sh
- src/tools/ftbench/ftbench.c
Changes:
1 | -# Variables
|
|
1 | +# Define a few important variables.
|
|
2 | 2 | FTBENCH_DIR = $(TOP_DIR)/src/tools/ftbench
|
3 | 3 | FTBENCH_SRC = $(FTBENCH_DIR)/ftbench.c
|
4 | 4 | FTBENCH_OBJ = $(OBJ_DIR)/bench.$(SO)
|
5 | 5 | FTBENCH_BIN = $(OBJ_DIR)/bench$E
|
6 | -FTBENCH_FLAG ?= -c 1000 -w 100
|
|
7 | 6 | INCLUDES = $(TOP_DIR)/include
|
8 | 7 | FONTS = $(wildcard $(FTBENCH_DIR)/fonts/*.ttf)
|
8 | + |
|
9 | + |
|
10 | +# Define objects.
|
|
9 | 11 | BASELINE_DIR = $(OBJ_DIR)/baseline/
|
10 | 12 | BENCHMARK_DIR = $(OBJ_DIR)/benchmark/
|
11 | -BASELINE = $(addprefix $(BASELINE_DIR), $(notdir $(FONTS:.ttf=.txt)))
|
|
12 | -BENCHMARK = $(addprefix $(BENCHMARK_DIR), $(notdir $(FONTS:.ttf=.txt)))
|
|
13 | 13 | BASELINE_INFO = $(BASELINE_DIR)info.txt
|
14 | 14 | BENCHMARK_INFO = $(BENCHMARK_DIR)info.txt
|
15 | 15 | HTMLCREATOR_SRC = $(FTBENCH_DIR)/src/tohtml.py
|
16 | 16 | HTMLCREATOR = $(OBJ_DIR)/tohtml.py
|
17 | 17 | HTMLFILE = $(OBJ_DIR)/benchmark.html
|
18 | 18 | |
19 | +# Define flags by default
|
|
20 | +FTBENCH_FLAG ?= -c 1000 -w 100
|
|
21 | + |
|
22 | + |
|
23 | +# Define test fonts all in the fonts folder.
|
|
24 | +BASELINE = $(addprefix $(BASELINE_DIR), $(notdir $(FONTS:.ttf=.txt)))
|
|
25 | +BENCHMARK = $(addprefix $(BENCHMARK_DIR), $(notdir $(FONTS:.ttf=.txt)))
|
|
26 | + |
|
27 | + |
|
19 | 28 | FT_INCLUDES := $(OBJ_BUILD) \
|
20 | 29 | $(INCLUDES)
|
21 | 30 | |
... | ... | @@ -23,12 +32,9 @@ COMPILE = $(CC) $(ANSIFLAGS) \ |
23 | 32 | $(INCLUDES:%=$I%) \
|
24 | 33 | $(CFLAGS)
|
25 | 34 | |
26 | -ifeq ($(PLATFORM),unix)
|
|
27 | - ifdef DEVEL_DIR
|
|
28 | - PLATFORM := unixdev
|
|
29 | - endif
|
|
30 | -endif
|
|
31 | - |
|
35 | +# Enable C99 for gcc to avoid warnings.
|
|
36 | +# Note that clang++ aborts with an error if we use `-std=C99',
|
|
37 | +# so check for `++' in $(CC) also.
|
|
32 | 38 | ifneq ($(findstring -pedantic,$(COMPILE)),)
|
33 | 39 | ifeq ($(findstring ++,$(CC)),)
|
34 | 40 | COMPILE += -std=c99
|
... | ... | @@ -38,12 +44,17 @@ endif |
38 | 44 | FTLIB := $(LIB_DIR)/$(LIBRARY).$A
|
39 | 45 | |
40 | 46 | ifeq ($(PLATFORM),unix)
|
47 | + # `LDFLAGS` comes from the `configure` script (via FreeType's
|
|
48 | + # `builds/unix/unix-cc.mk`), holding all linker flags necessary to
|
|
49 | + # link the FreeType library.
|
|
41 | 50 | LINK_CMD = $(LIBTOOL) --mode=link $(CCraw) \
|
42 | 51 | $(subst /,$(COMPILER_SEP),$(LDFLAGS))
|
43 | 52 | LINK_LIBS = $(subst /,$(COMPILER_SEP),$(FTLIB) $(EFENCE))
|
44 | 53 | else
|
45 | 54 | LINK_CMD = $(CC) $(subst /,$(COMPILER_SEP),$(LDFLAGS))
|
46 | 55 | ifeq ($(PLATFORM),unixdev)
|
56 | + # For the pure `make` call (without using `configure`) we have to add
|
|
57 | + # all needed libraries manually.
|
|
47 | 58 | LINK_LIBS := $(subst /,$(COMPILER_SEP),$(FTLIB) $(EFENCE)) \
|
48 | 59 | -lm -lrt -lz -lbz2 -lpthread
|
49 | 60 | LINK_LIBS += $(shell pkg-config --libs libpng)
|
... | ... | @@ -55,10 +66,15 @@ else |
55 | 66 | endif
|
56 | 67 | endif
|
57 | 68 | |
69 | +# Only on Windows we might fall back on GDI+ for PNG saving
|
|
58 | 70 | ifeq ($(OS),Windows_NT)
|
59 | 71 | LINK_LIBS += -lgdiplus
|
60 | 72 | endif
|
61 | 73 | |
74 | +####################################################################
|
|
75 | +#
|
|
76 | +# POSIX TERMIOS: Do not define if you use OLD U*ix like 4.2BSD.
|
|
77 | +#
|
|
62 | 78 | ifeq ($(PLATFORM),unix)
|
63 | 79 | EXTRAFLAGS = $DUNIX $DHAVE_POSIX_TERMIOS
|
64 | 80 | endif
|
... | ... | @@ -73,6 +89,7 @@ INCLUDES := $(subst /,$(COMPILER_SEP),$(FT_INCLUDES)) |
73 | 89 | $(BASELINE_DIR) $(BENCHMARK_DIR):
|
74 | 90 | @mkdir -p $@
|
75 | 91 | |
92 | +# Create ftbench object
|
|
76 | 93 | $(FTBENCH_OBJ): $(FTBENCH_SRC)
|
77 | 94 | @$(COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<) $(EXTRAFLAGS)
|
78 | 95 | @echo "Object created."
|
... | ... | @@ -83,6 +100,7 @@ $(FTBENCH_BIN): $(FTBENCH_OBJ) |
83 | 100 | @$(LINK_CMD) $T$(subst /,$(COMPILER_SEP),$@ $<) $(LINK_LIBS)
|
84 | 101 | @echo "Built."
|
85 | 102 | |
103 | +# Copy tohtml.py into objs folder
|
|
86 | 104 | .PHONY: copy-html-script
|
87 | 105 | copy-html-script:
|
88 | 106 | @cp $(HTMLCREATOR_SRC) $(OBJ_DIR)
|
1 | +ftbench
|
|
2 | +========
|
|
3 | + |
|
4 | +ftbench is a program designed to run FreeType benchmarks. It accepts various options and a font name to run specific tests on font rendering operations.
|
|
5 | + |
|
6 | +Each test may involve tasks such as:
|
|
7 | + |
|
8 | +. Initializing the library
|
|
9 | +. Opening the font file
|
|
10 | +. Loading and optionally rendering each glyph
|
|
11 | +. Comparing results with cached versions (if available)
|
|
12 | +. Configuring specific charmap indices, load flags, etc.
|
|
13 | + |
|
14 | +Usage is time-limited or can be explicitly set to use a maximum number of iterations per test.
|
|
15 | + |
|
16 | + |
|
17 | +Command line options
|
|
18 | +--------------------
|
|
19 | + |
|
20 | +-C Compare with cached version (if available).
|
|
21 | +-c N Use at most N iterations for each test (0 means time-limited).
|
|
22 | +-e E Set specific charmap index E.
|
|
23 | +-f L Use hex number L as load flags (see FT_LOAD_XXX'). -H NAME Use PS hinting engine NAME (default is adobe').
|
|
24 | +-I VER Use TT interpreter version VER (default is version 40).
|
|
25 | +-i I-J Forward or reverse range of glyph indices to use.
|
|
26 | +-l N Set LCD filter to N (default is 0: none).
|
|
27 | +-m M Set maximum cache size to M KiByte (default is 1024).
|
|
28 | +-p Preload font file in memory.
|
|
29 | +-r N Set render mode to N (default is 0: normal).
|
|
30 | +-s S Use S ppem as face size (default is 10ppem).
|
|
31 | +-t T Use at most T seconds per bench (default is 2).
|
|
32 | +-w N Use N iterations for warming up before each test.
|
|
33 | + |
|
34 | +-b tests Perform chosen tests (default is all).
|
|
35 | +-v Show version.
|
|
36 | + |
|
37 | +Compilation
|
|
38 | +-----------
|
|
39 | + |
|
40 | +make baseline To create a baseline for your benchmarks, use the `make baseline` command. This will compile the ftbench.c and create a set of baseline measurements in the objs/baseline/ directory.
|
|
41 | + |
|
42 | +make benchmark To run the benchmarks, use the `make benchmark` command. The results will be stored in the objs/benchmark/ directory. It will copy tohtml.py script to objs/ and generate a html file.
|
|
43 | + |
|
44 | +make clean-benchmark To remove all generated benchmark files and clean the objs directory, use the `make clean-benchmark` command.
|
|
45 | + |
1 | 1 | #!/bin/bash
|
2 | +# This tool is to subset fonts.
|
|
2 | 3 | |
3 | 4 | # Define the Unicode range
|
4 | 5 | unicodes="U+0021-007E"
|
... | ... | @@ -259,7 +259,8 @@ |
259 | 259 | #define TIMER_GET( timer ) ( timer )->total
|
260 | 260 | #define TIMER_RESET( timer ) ( timer )->total = 0
|
261 | 261 | |
262 | -#define CHUNK_SIZE 50
|
|
262 | +#define ITER 1000
|
|
263 | +#define CHUNK_SIZE 100
|
|
263 | 264 | |
264 | 265 | int compare(const void* a, const void* b) {
|
265 | 266 | if (*(double*)a > *(double*)b) return 1;
|
... | ... | @@ -273,7 +274,10 @@ static void benchmark(FT_Face face, btest_t* test, int max_iter, double max_time |
273 | 274 | double total_time = 0.0;
|
274 | 275 | btimer_t timer;
|
275 | 276 | |
276 | - int NUM_CHUNKS = max_iter / CHUNK_SIZE;
|
|
277 | + if(max_iter == 0)
|
|
278 | + max_iter = ITER;
|
|
279 | + |
|
280 | + int NUM_CHUNKS = max_iter / CHUNK_SIZE; // split the total iterations into chunks to remove the outliers.
|
|
277 | 281 | double medians[NUM_CHUNKS];
|
278 | 282 | |
279 | 283 | // Cache
|
... | ... | @@ -961,7 +965,6 @@ static void benchmark(FT_Face face, btest_t* test, int max_iter, double max_time |
961 | 965 | ps_hinting_engine_names[ps_hinting_engines[0]],
|
962 | 966 | ps_hinting_engine_names[ps_hinting_engines[1]] );
|
963 | 967 | |
964 | - // TODO: add here -w option
|
|
965 | 968 | fprintf( stderr,
|
966 | 969 | "\n"
|
967 | 970 | "ftbench: run FreeType benchmarks\n"
|
... | ... | @@ -1000,6 +1003,7 @@ static void benchmark(FT_Face face, btest_t* test, int max_iter, double max_time |
1000 | 1003 | FACE_SIZE );
|
1001 | 1004 | fprintf( stderr,
|
1002 | 1005 | " -t T Use at most T seconds per bench (default is %.0f).\n"
|
1006 | + " -w N Use N iterations for warming up before each test\n"
|
|
1003 | 1007 | "\n"
|
1004 | 1008 | " -b tests Perform chosen tests (default is all):\n",
|
1005 | 1009 | BENCH_TIME );
|