bench(string): add bench_string.c vs glibc/musl
System-headers-only harness timing the five L1 string functions (strlen, strcmp, memcpy, memmove, memset) at 8- and 64-byte inputs. Calls go through volatile function pointers to defeat builtin substitution and LICM hoisting; correctness self-asserts route through the same pointers. Prints FUNC@SIZE ns/call lines. bench_string uses empty per-target CPPFLAGS (no -I include) so it links against whichever libc --with-libc= selects; the bench target runs it always and bench_vlibc only under BENCH_LINK_VLIBC. Both programs relink when config.status changes, so a reconfigure cannot silently reuse a binary from the previous libc. Measured vs glibc 2.44 (median of 3 runs): mem* 1.0-3.3x, strlen/strcmp 3.2-3.9x — word-at-a-time vs AVX2, all sane. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
This commit is contained in:
+28
-2
@@ -5,23 +5,49 @@ AM_CFLAGS = @VLIBC_CFLAGS@
|
||||
|
||||
# Built only on demand (via `make bench`), so `make all` does not need the
|
||||
# library to be built first.
|
||||
EXTRA_PROGRAMS = bench_vlibc
|
||||
EXTRA_PROGRAMS = bench_vlibc bench_string
|
||||
bench_vlibc_SOURCES = bench_vlibc.c
|
||||
bench_string_SOURCES = bench_string.c
|
||||
|
||||
# bench_string is a system-headers-only translation unit (it times whichever
|
||||
# libc it is linked against), so it must NOT inherit AM_CPPFLAGS: -I include
|
||||
# would pull vlibc's self-contained <stddef.h>/<string.h> into the same TU as
|
||||
# the system <stdio.h>/<time.h> and double-define size_t/NULL/offsetof.
|
||||
# bench_vlibc keeps the inherited -I include.
|
||||
bench_string_CPPFLAGS =
|
||||
|
||||
# By default benchmarks link against vlibc itself. --with-libc=glibc links the
|
||||
# same harness against the system glibc; --with-libc=musl builds it with
|
||||
# musl-gcc for the musl reference.
|
||||
if BENCH_LINK_VLIBC
|
||||
bench_vlibc_LDADD = ../libvlibc.la
|
||||
bench_string_LDADD = ../libvlibc.la
|
||||
else
|
||||
bench_vlibc_LDADD =
|
||||
bench_string_LDADD =
|
||||
endif
|
||||
|
||||
if BENCH_LINK_MUSL
|
||||
CC = $(MUSL_CC)
|
||||
endif
|
||||
|
||||
bench: bench_vlibc
|
||||
# Relink whenever the configuration changes (autogen.sh reruns configure and
|
||||
# rewrites config.status). --with-libc only affects the link (LDADD), and the
|
||||
# objects are compile-time identical, so make would otherwise reuse a stale
|
||||
# binary from the previous configuration and the wrong libc would be measured.
|
||||
EXTRA_bench_string_DEPENDENCIES = $(top_builddir)/config.status
|
||||
EXTRA_bench_vlibc_DEPENDENCIES = $(top_builddir)/config.status
|
||||
|
||||
# bench_vlibc.c calls vlibc_version(), which exists only in vlibc — under
|
||||
# --with-libc=glibc/musl it cannot link, so it is built and run only in the
|
||||
# vlibc build. bench_string links either way and runs always.
|
||||
if BENCH_LINK_VLIBC
|
||||
bench: bench_vlibc bench_string
|
||||
./bench_vlibc
|
||||
./bench_string
|
||||
else
|
||||
bench: bench_string
|
||||
./bench_string
|
||||
endif
|
||||
|
||||
.PHONY: bench
|
||||
|
||||
Reference in New Issue
Block a user