d8307d
objpfx = $(prefix)/$(ver)/usr/libexec/glibc-benchtests/
d8307d
d8307d
bench-math := acos acosh asin asinh atan atanh cos cosh exp exp2 ffs ffsll \
d8307d
	      log log2 modf pow rint sin sincos sinh sqrt tan tanh
d8307d
d8307d
bench-pthread := pthread_once
d8307d
d8307d
bench := $(bench-math) $(bench-pthread)
d8307d
d8307d
run-bench := $(prefix)/$(ver)/lib64/ld-linux-x86-64.so.2 --library-path $(prefix)/$(ver)/lib64 $${run}
d8307d
d8307d
# String function benchmarks.
d8307d
string-bench := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
d8307d
		mempcpy memset rawmemchr stpcpy stpncpy strcasecmp strcasestr \
d8307d
		strcat strchr strchrnul strcmp strcpy strcspn strlen \
d8307d
		strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
d8307d
		strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok
d8307d
string-bench-all := $(string-bench)
d8307d
d8307d
stdlib-bench := strtod
d8307d
d8307d
benchset := $(string-bench-all) $(stdlib-bench)
d8307d
d8307d
bench-malloc := malloc-thread
d8307d
d8307d
binaries-bench := $(addprefix $(objpfx)bench-,$(bench))
d8307d
binaries-benchset := $(addprefix $(objpfx)bench-,$(benchset))
d8307d
binaries-bench-malloc := $(addprefix $(objpfx)bench-,$(bench-malloc))
d8307d
d8307d
DETAILED_OPT :=
d8307d
d8307d
ifdef DETAILED
d8307d
	DETAILED_OPT := -d
d8307d
endif
d8307d
d8307d
bench: bench-set bench-func bench-malloc
d8307d
d8307d
bench-set: $(binaries-benchset)
d8307d
	for run in $^; do \
d8307d
	  outfile=$(prefix)/$$(basename $${run}.$(ver).out); \
d8307d
	  echo "Running $${run}"; \
d8307d
	  $(run-bench) > $${outfile}.tmp; \
d8307d
	  mv $${outfile}{.tmp,}; \
d8307d
	done
d8307d
d8307d
bench-malloc: $(binaries-bench-malloc)
d8307d
	run=$(objpfx)bench-malloc-thread; \
d8307d
	outfile=$(prefix)/$$(basename $${run}.$(ver).out); \
d8307d
	for thr in 1 8 16 32; do \
d8307d
	  echo "Running $${run} $${thr}"; \
d8307d
	  $(run-bench) $${thr} > $${outfile}.tmp; \
d8307d
	  mv $${outfile}{.tmp,}; \
d8307d
	done
d8307d
d8307d
# Build and execute the benchmark functions.  This target generates JSON
d8307d
# formatted bench.out.  Each of the programs produce independent JSON output,
d8307d
# so one could even execute them individually and process it using any JSON
d8307d
# capable language or tool.
d8307d
bench-func: $(binaries-bench)
d8307d
	{ echo "{\"timing_type\": \"hp-timing\","; \
d8307d
	echo " \"functions\": {"; \
d8307d
	for run in $^; do \
d8307d
	  if ! [ "x$${run}" = "x$<" ]; then \
d8307d
	    echo ","; \
d8307d
	  fi; \
d8307d
	  echo "Running $${run}" >&2; \
d8307d
	  $(run-bench) $(DETAILED_OPT); \
d8307d
	done; \
d8307d
	echo; \
d8307d
	echo " }"; \
d8307d
	echo "}"; } > $(prefix)/bench.$(ver).out-tmp; \
d8307d
	if [ -f $(prefix)/bench.$(ver).out ]; then \
d8307d
	  mv -f $(prefix)/bench.$(ver).out{,.old}; \
d8307d
	fi; \
d8307d
	mv -f $(prefix)/bench.$(ver).out{-tmp,}
d8307d
#	scripts/validate_benchout.py bench.out \
d8307d
#		scripts/benchout.schema.json