1 # Copyright (C) 2013-2017 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
4 # The GNU C Library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # The GNU C Library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with the GNU C Library; if not, see
16 # <http://www.gnu.org/licenses/>.
18 # Makefile for benchmark tests. The only useful target here is `bench`.
19 # Add benchmark functions in alphabetical order.
24 bench-math
:= acos acosh asin asinh atan atanh cos cosh exp exp2 log log2 \
25 modf pow rint sin sincos sinh sqrt tan tanh fmin fmax fminf \
26 fmaxf powf trunc truncf expf exp2f logf log2f sincosf sinf \
29 bench-pthread
:= pthread_once thread_create
31 bench-string
:= ffs ffsll
33 bench
:= $(bench-math
) $(bench-pthread
) $(bench-string
)
35 # String function benchmarks.
36 string-benchset
:= bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
37 mempcpy memset rawmemchr stpcpy stpncpy strcasecmp strcasestr \
38 strcat strchr strchrnul strcmp strcpy strcspn strlen \
39 strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
40 strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok \
41 strcoll memcpy-large memcpy-random memmove-large memset-large \
42 memcpy-walk memset-walk memmove-walk
44 # Build and run locale-dependent benchmarks only if we're building natively.
45 ifeq (no
,$(cross-compiling
))
46 wcsmbs-benchset
:= wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat \
47 wcscmp wcsncmp wcschr wcschrnul wcsrchr wcsspn wcspbrk wcscspn \
48 wmemchr wmemset wmemcmp
53 string-benchset-all
:= $(string-benchset
) ${wcsmbs-benchset
}
55 ifeq (no
,$(cross-compiling
))
56 # We have to generate locales
57 LOCALES
:= en_US.UTF-8 tr_TR.UTF-8 cs_CZ.UTF-8 fa_IR.UTF-8 fr_FR.UTF-8 \
58 ja_JP.UTF-8 si_LK.UTF-8 en_GB.UTF-8 vi_VN.UTF-8 ar_SA.UTF-8 \
59 da_DK.UTF-8 pl_PL.UTF-8 pt_PT.UTF-8 el_GR.UTF-8 ru_RU.UTF-8 \
60 he_IL.UTF-8 is_IS.UTF-8 es_ES.UTF-8 hi_IN.UTF-8 sv_SE.UTF-8 \
61 hu_HU.UTF-8 it_IT.UTF-8 sr_RS.UTF-8 zh_CN.UTF-8
62 include ..
/gen-locales.mk
65 stdlib-benchset
:= strtod
67 stdio-common-benchset
:= sprintf
69 math-benchset
:= math-inlines
71 benchset
:= $(string-benchset-all
) $(stdlib-benchset
) $(stdio-common-benchset
) \
74 CFLAGS-bench-ffs.c
+= -fno-builtin
75 CFLAGS-bench-ffsll.c
+= -fno-builtin
76 CFLAGS-bench-sqrt.c
+= -fno-builtin
77 CFLAGS-bench-fmin.c
+= -fno-builtin
78 CFLAGS-bench-fminf.c
+= -fno-builtin
79 CFLAGS-bench-fmax.c
+= -fno-builtin
80 CFLAGS-bench-fmaxf.c
+= -fno-builtin
81 CFLAGS-bench-trunc.c
+= -fno-builtin
82 CFLAGS-bench-truncf.c
+= -fno-builtin
84 bench-malloc
:= malloc-thread
86 $(addprefix $(objpfx
)bench-
,$(bench-math
)): $(libm
)
87 $(addprefix $(objpfx
)bench-
,$(math-benchset
)): $(libm
)
88 $(addprefix $(objpfx
)bench-
,$(bench-pthread
)): $(shared-thread-library
)
89 $(objpfx
)bench-malloc-thread
: $(shared-thread-library
)
93 # Rules to build and execute the benchmarks. Do not put any benchmark
94 # parameters beyond this point.
96 # We don't want the benchmark programs to run in parallel since that could
97 # affect their performance.
100 bench-extra-objs
= json-lib.o
102 extra-objs
+= $(bench-extra-objs
)
103 others-extras
= $(bench-extra-objs
)
107 binaries-bench
:= $(addprefix $(objpfx
)bench-
,$(bench
))
108 binaries-benchset
:= $(addprefix $(objpfx
)bench-
,$(benchset
))
109 binaries-bench-malloc
:= $(addprefix $(objpfx
)bench-
,$(bench-malloc
))
111 # The default duration: 10 seconds.
112 ifndef BENCH_DURATION
116 CPPFLAGS-nonlib
+= -DDURATION
=$(BENCH_DURATION
)
118 # Use clock_gettime to measure performance of functions. The default is to use
119 # HP_TIMING if it is available.
120 ifdef USE_CLOCK_GETTIME
121 CPPFLAGS-nonlib
+= -DUSE_CLOCK_GETTIME
130 # This makes sure CPPFLAGS-nonlib and CFLAGS-nonlib are passed
131 # for all these modules.
132 cpp-srcs-left
:= $(binaries-benchset
:=.c
) $(binaries-bench
:=.c
) \
133 $(binaries-bench-malloc
:=.c
)
135 include $(patsubst %,$(..
)libof-iterator.mk
,$(cpp-srcs-left
))
137 bench-deps
:= bench-skeleton.c bench-timing.h Makefile
139 run-bench
= $(test-wrapper-env
) \
141 $($*-ENV
) $(test-via-rtld-prefix
) $${run}
143 timing-type
:= $(objpfx
)bench-timing-type
146 rm -f
$(binaries-bench
) $(addsuffix .o
,$(binaries-bench
))
147 rm -f
$(binaries-benchset
) $(addsuffix .o
,$(binaries-benchset
))
148 rm -f
$(binaries-bench-malloc
) $(addsuffix .o
,$(binaries-bench-malloc
))
149 rm -f
$(timing-type
) $(addsuffix .o
,$(timing-type
))
150 rm -f
$(addprefix $(objpfx
),$(bench-extra-objs
))
152 # Define the bench target only if the target has a usable python installation.
154 bench
: bench-build bench-set bench-func bench-malloc
157 @echo
"The bench target needs python to run."
161 # Target to only build the benchmark without running it. We generate locales
162 # only if we're building natively.
163 ifeq (no
,$(cross-compiling
))
164 bench-build
: $(gen-locales
) $(timing-type
) $(binaries-bench
) \
165 $(binaries-benchset
) $(binaries-bench-malloc
)
167 bench-build
: $(timing-type
) $(binaries-bench
) $(binaries-benchset
) \
168 $(binaries-bench-malloc
)
171 bench-set
: $(binaries-benchset
)
173 echo
"Running $${run}"; \
174 $(run-bench
) > $${run}.out
; \
177 bench-malloc
: $(binaries-bench-malloc
)
178 run
=$(objpfx
)bench-malloc-thread
; \
179 for thr in
1 8 16 32; do \
180 echo
"Running $${run} $${thr}"; \
181 $(run-bench
) $${thr} > $${run}-$${thr}.out
; \
184 # Build and execute the benchmark functions. This target generates JSON
185 # formatted bench.out. Each of the programs produce independent JSON output,
186 # so one could even execute them individually and process it using any JSON
187 # capable language or tool.
188 bench-func
: $(binaries-bench
)
189 { timing_type
=$$($(timing-type
)); \
190 echo
"{\"timing_type\": \"$${timing_type}\","; \
191 echo
" \"functions\": {"; \
193 if
! [ "x$${run}" = "x$<" ]; then \
196 echo
"Running $${run}" >&2; \
197 $(run-bench
) $(DETAILED_OPT
); \
201 echo
"}"; } > $(objpfx
)bench.out-tmp
; \
202 if
[ -f
$(objpfx
)bench.out
]; then \
203 mv
-f
$(objpfx
)bench.out
$(objpfx
)bench.out.old
; \
205 mv
-f
$(objpfx
)bench.out-tmp
$(objpfx
)bench.out
206 $(PYTHON
) scripts
/validate_benchout.py
$(objpfx
)bench.out \
207 scripts
/benchout.schema.json
209 $(timing-type
) $(binaries-bench
) $(binaries-benchset
) \
210 $(binaries-bench-malloc
): %: %.o
$(objpfx
)json-lib.o \
211 $(link-extra-libs-tests
) \
212 $(sort $(filter $(common-objpfx
)lib
%,$(link-libc
))) \
213 $(addprefix $(csu-objpfx
),start.o
) $(+preinit
) $(+postinit
)
216 $(objpfx
)bench-
%.c
: %-inputs
$(bench-deps
)
217 { if
[ -n
"$($*-INCLUDE)" ]; then \
220 $(PYTHON
) scripts
/bench.py
$(patsubst %-inputs
,%,$<); } > $@
-tmp