]> git.ipfire.org Git - thirdparty/glibc.git/blame - benchtests/Makefile
benchtests: Expand range of tests names in schema.json
[thirdparty/glibc.git] / benchtests / Makefile
CommitLineData
bfff8b1b 1# Copyright (C) 2013-2017 Free Software Foundation, Inc.
8cfdb7e0
SP
2# This file is part of the GNU C Library.
3
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.
8
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.
13
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/>.
17
8cfdb7e0 18# Makefile for benchmark tests. The only useful target here is `bench`.
3ce9e010 19# Add benchmark functions in alphabetical order.
8cfdb7e0 20
8cfdb7e0 21subdir := benchtests
a5f891ac
JM
22
23include ../Makeconfig
aad287f3 24bench-math := acos acosh asin asinh atan atanh cos cosh exp exp2 log log2 \
da16c9b5 25 modf pow rint sin sincos sinh sqrt tan tanh fmin fmax fminf \
077ee129
RS
26 fmaxf powf trunc truncf expf exp2f logf log2f sincosf sinf \
27 cosf
bb9c256f 28
0edbf123 29bench-pthread := pthread_once thread_create
bb9c256f 30
aad287f3
SP
31bench-string := ffs ffsll
32
33bench := $(bench-math) $(bench-pthread) $(bench-string)
3ce9e010 34
c1f75dc3 35# String function benchmarks.
aad287f3
SP
36string-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 \
9ec87fd2 41 strcoll memcpy-large memcpy-random memmove-large memset-large \
5bfb0404 42 memcpy-walk memset-walk memmove-walk
2d304f3c
SP
43
44# Build and run locale-dependent benchmarks only if we're building natively.
45ifeq (no,$(cross-compiling))
aad287f3
SP
46wcsmbs-benchset := wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat \
47 wcscmp wcsncmp wcschr wcschrnul wcsrchr wcsspn wcspbrk wcscspn \
48 wmemchr wmemset wmemcmp
2d304f3c
SP
49else
50wcsmbs-benchset :=
51endif
52
aad287f3 53string-benchset-all := $(string-benchset) ${wcsmbs-benchset}
c1f75dc3 54
2d304f3c 55ifeq (no,$(cross-compiling))
60ccaf75
LH
56# We have to generate locales
57LOCALES := 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 \
20003c49 60 he_IL.UTF-8 is_IS.UTF-8 es_ES.UTF-8 hi_IN.UTF-8 sv_SE.UTF-8 \
60ccaf75
LH
61 hu_HU.UTF-8 it_IT.UTF-8 sr_RS.UTF-8 zh_CN.UTF-8
62include ../gen-locales.mk
2d304f3c 63endif
60ccaf75 64
aad287f3 65stdlib-benchset := strtod
450a2e2d 66
aad287f3 67stdio-common-benchset := sprintf
608f8971 68
cb2f668d
WD
69math-benchset := math-inlines
70
aad287f3 71benchset := $(string-benchset-all) $(stdlib-benchset) $(stdio-common-benchset) \
cb2f668d 72 $(math-benchset)
c1f75dc3 73
f6c55796
WN
74CFLAGS-bench-ffs.c += -fno-builtin
75CFLAGS-bench-ffsll.c += -fno-builtin
7a8330c0 76CFLAGS-bench-sqrt.c += -fno-builtin
5d1f604a 77CFLAGS-bench-fmin.c += -fno-builtin
da16c9b5 78CFLAGS-bench-fminf.c += -fno-builtin
5d1f604a 79CFLAGS-bench-fmax.c += -fno-builtin
da16c9b5 80CFLAGS-bench-fmaxf.c += -fno-builtin
eb375def
JM
81CFLAGS-bench-trunc.c += -fno-builtin
82CFLAGS-bench-truncf.c += -fno-builtin
f6c55796 83
b01ee67c
WN
84bench-malloc := malloc-thread
85
79520f4b 86$(addprefix $(objpfx)bench-,$(bench-math)): $(libm)
cb2f668d 87$(addprefix $(objpfx)bench-,$(math-benchset)): $(libm)
79520f4b 88$(addprefix $(objpfx)bench-,$(bench-pthread)): $(shared-thread-library)
b01ee67c 89$(objpfx)bench-malloc-thread: $(shared-thread-library)
7849ff93 90
8fc1bee5
SP
91\f
92
93# Rules to build and execute the benchmarks. Do not put any benchmark
94# parameters beyond this point.
95
c1f75dc3
SP
96# We don't want the benchmark programs to run in parallel since that could
97# affect their performance.
98.NOTPARALLEL:
99
4504783c
FW
100bench-extra-objs = json-lib.o
101
102extra-objs += $(bench-extra-objs)
103others-extras = $(bench-extra-objs)
104
8cfdb7e0 105include ../Rules
8fc1bee5
SP
106
107binaries-bench := $(addprefix $(objpfx)bench-,$(bench))
c1f75dc3 108binaries-benchset := $(addprefix $(objpfx)bench-,$(benchset))
b01ee67c 109binaries-bench-malloc := $(addprefix $(objpfx)bench-,$(bench-malloc))
8fc1bee5 110
d569c6ee
SP
111# The default duration: 10 seconds.
112ifndef BENCH_DURATION
113BENCH_DURATION := 10
114endif
115
50b818bf 116CPPFLAGS-nonlib += -DDURATION=$(BENCH_DURATION)
d569c6ee 117
43fe811b
SP
118# Use clock_gettime to measure performance of functions. The default is to use
119# HP_TIMING if it is available.
120ifdef USE_CLOCK_GETTIME
121CPPFLAGS-nonlib += -DUSE_CLOCK_GETTIME
122endif
123
56737508
SP
124DETAILED_OPT :=
125
126ifdef DETAILED
127DETAILED_OPT := -d
128endif
129
4856bcd2
SP
130# This makes sure CPPFLAGS-nonlib and CFLAGS-nonlib are passed
131# for all these modules.
b01ee67c
WN
132cpp-srcs-left := $(binaries-benchset:=.c) $(binaries-bench:=.c) \
133 $(binaries-bench-malloc:=.c)
4856bcd2 134lib := nonlib
2bfdaedd 135include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
4856bcd2 136
43fe811b 137bench-deps := bench-skeleton.c bench-timing.h Makefile
acb4325f 138
8fc1bee5 139run-bench = $(test-wrapper-env) \
8540f6d2 140 $(run-program-env) \
87da630b 141 $($*-ENV) $(test-via-rtld-prefix) $${run}
8fc1bee5 142
cb5e4aad
SP
143timing-type := $(objpfx)bench-timing-type
144
a2964074
SP
145bench-clean:
146 rm -f $(binaries-bench) $(addsuffix .o,$(binaries-bench))
c1f75dc3 147 rm -f $(binaries-benchset) $(addsuffix .o,$(binaries-benchset))
b01ee67c 148 rm -f $(binaries-bench-malloc) $(addsuffix .o,$(binaries-bench-malloc))
cb5e4aad 149 rm -f $(timing-type) $(addsuffix .o,$(timing-type))
d7aea0cf 150 rm -f $(addprefix $(objpfx),$(bench-extra-objs))
c1f75dc3 151
8ce8299f
SP
152# Define the bench target only if the target has a usable python installation.
153ifdef PYTHON
2d304f3c 154bench: bench-build bench-set bench-func bench-malloc
8ce8299f
SP
155else
156bench:
157 @echo "The bench target needs python to run."
158 @exit 1
159endif
160
2d304f3c
SP
161# Target to only build the benchmark without running it. We generate locales
162# only if we're building natively.
163ifeq (no,$(cross-compiling))
164bench-build: $(gen-locales) $(timing-type) $(binaries-bench) \
165 $(binaries-benchset) $(binaries-bench-malloc)
166else
167bench-build: $(timing-type) $(binaries-bench) $(binaries-benchset) \
168 $(binaries-bench-malloc)
169endif
c1f75dc3
SP
170
171bench-set: $(binaries-benchset)
172 for run in $^; do \
173 echo "Running $${run}"; \
174 $(run-bench) > $${run}.out; \
175 done
a2964074 176
b01ee67c
WN
177bench-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; \
182 done
183
cb5e4aad
SP
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.
c1f75dc3 188bench-func: $(binaries-bench)
970c602a
WN
189 { timing_type=$$($(timing-type)); \
190 echo "{\"timing_type\": \"$${timing_type}\","; \
191 echo " \"functions\": {"; \
cb5e4aad
SP
192 for run in $^; do \
193 if ! [ "x$${run}" = "x$<" ]; then \
194 echo ","; \
195 fi; \
206a6699 196 echo "Running $${run}" >&2; \
56737508 197 $(run-bench) $(DETAILED_OPT); \
cb5e4aad 198 done; \
970c602a
WN
199 echo; \
200 echo " }"; \
cb5e4aad 201 echo "}"; } > $(objpfx)bench.out-tmp; \
8fc1bee5
SP
202 if [ -f $(objpfx)bench.out ]; then \
203 mv -f $(objpfx)bench.out $(objpfx)bench.out.old; \
204 fi; \
205 mv -f $(objpfx)bench.out-tmp $(objpfx)bench.out
67fc5637 206 $(PYTHON) scripts/validate_benchout.py $(objpfx)bench.out \
42b1161e 207 scripts/benchout.schema.json
8fc1bee5 208
b01ee67c
WN
209$(timing-type) $(binaries-bench) $(binaries-benchset) \
210 $(binaries-bench-malloc): %: %.o $(objpfx)json-lib.o \
009ba649 211 $(link-extra-libs-tests) \
8fc1bee5
SP
212 $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
213 $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
87da630b 214 $(+link-tests)
8fc1bee5 215
acb4325f 216$(objpfx)bench-%.c: %-inputs $(bench-deps)
8fc1bee5
SP
217 { if [ -n "$($*-INCLUDE)" ]; then \
218 cat $($*-INCLUDE); \
219 fi; \
67fc5637 220 $(PYTHON) scripts/bench.py $(patsubst %-inputs,%,$<); } > $@-tmp
8fc1bee5 221 mv -f $@-tmp $@