Use HP_TIMING for benchmarks if available
[platform/upstream/glibc.git] / benchtests / Makefile
1 # Copyright (C) 2013 Free Software Foundation, Inc.
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
18
19 # Makefile for benchmark tests.  The only useful target here is `bench`.
20
21 # Adding a new function `foo`:
22 # ---------------------------
23
24 # - Append the function name to the bench variable
25
26 # - Define foo-ARGLIST as a colon separated list of types of the input
27 #   arguments.  Use `void` if function does not take any inputs.  Put in quotes
28 #   if the input argument is a pointer, e.g.:
29
30 #      malloc-ARGLIST: "void *"
31
32 # - Define foo-RET as the type the function returns.  Skip if the function
33 #   returns void.  One could even skip foo-ARGLIST if the function does not
34 #   take any inputs AND the function returns void.
35
36
37 # - Make a file called `foo-inputs` with one input value per line, an input
38 #   being a comma separated list of arguments to be passed into the function.
39 #   See pow-inputs for an example.
40
41 subdir := benchtests
42 bench := exp pow rint sin cos tan atan modf
43
44 exp-ARGLIST = double
45 exp-RET = double
46 LDFLAGS-bench-exp = -lm
47
48 pow-ARGLIST = double:double
49 pow-RET = double
50 LDFLAGS-bench-pow = -lm
51
52 rint-ARGLIST = double
53 rint-RET = double
54 LDFLAGS-bench-rint = -lm
55
56 sin-ARGLIST = double
57 sin-RET = double
58 LDFLAGS-bench-sin = -lm
59
60 cos-ARGLIST = double
61 cos-RET = double
62 LDFLAGS-bench-cos = -lm
63
64 tan-ARGLIST = double
65 tan-RET = double
66 LDFLAGS-bench-tan = -lm
67
68 atan-ARGLIST = double
69 atan-RET = double
70 LDFLAGS-bench-atan = -lm
71
72 \f
73
74 # Rules to build and execute the benchmarks.  Do not put any benchmark
75 # parameters beyond this point.
76
77 include ../Makeconfig
78 include ../Rules
79
80 binaries-bench := $(addprefix $(objpfx)bench-,$(bench))
81
82 # The default duration: 10 seconds.
83 ifndef BENCH_DURATION
84 BENCH_DURATION := 10
85 endif
86
87 CPPFLAGS-nonlib = -DDURATION=$(BENCH_DURATION)
88
89 # Use clock_gettime to measure performance of functions.  The default is to use
90 # HP_TIMING if it is available.
91 ifdef USE_CLOCK_GETTIME
92 CPPFLAGS-nonlib += -DUSE_CLOCK_GETTIME
93 endif
94
95 # This makes sure CPPFLAGS-nonlib and CFLAGS-nonlib are passed
96 # for all these modules.
97 cpp-srcs-left := $(binaries-bench:=.c)
98 lib := nonlib
99 include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
100
101 bench-deps := bench-skeleton.c bench-timing.h Makefile
102
103 run-bench = $(test-wrapper-env) \
104             GCONV_PATH=$(common-objpfx)iconvdata LC_ALL=C \
105             $($*-ENV) $(rtld-prefix) $${run}
106
107 bench-clean:
108         rm -f $(binaries-bench) $(addsuffix .o,$(binaries-bench))
109
110 bench: $(binaries-bench)
111         { for run in $^; do \
112           echo "Running $${run}" >&2; \
113           $(run-bench); \
114         done; } > $(objpfx)bench.out-tmp; \
115         if [ -f $(objpfx)bench.out ]; then \
116           mv -f $(objpfx)bench.out $(objpfx)bench.out.old; \
117         fi; \
118         mv -f $(objpfx)bench.out-tmp $(objpfx)bench.out
119
120 $(binaries-bench): %: %.o \
121   $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
122   $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
123         $(+link)
124
125 $(objpfx)bench-%.c: %-inputs $(bench-deps)
126         { if [ -n "$($*-INCLUDE)" ]; then \
127           cat $($*-INCLUDE); \
128         fi; \
129         $(..)scripts/bench.pl $(patsubst %-inputs,%,$<) \
130           $($*-ARGLIST) $($*-RET); } > $@-tmp
131         mv -f $@-tmp $@