Skip to content

Commit

Permalink
checksum_benchmarks.sh: misc improvements
Browse files Browse the repository at this point in the history
- Increase size of test file to 250 MB for more accurate results
- Disable x86-32 test by default
- Support specifying extra cmake flags
- Code cleanups
  • Loading branch information
ebiggers committed Mar 4, 2024
1 parent 677ebe7 commit 1bc5a19
Showing 1 changed file with 73 additions and 33 deletions.
106 changes: 73 additions & 33 deletions scripts/checksum_benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -eu -o pipefail

have_cpu_feature() {
__have_cpu_feature() {
local feature="$1"
local tag
case $ARCH in
Expand All @@ -19,7 +19,7 @@ have_cpu_feature() {
have_cpu_features() {
local feature
for feature; do
have_cpu_feature "$feature" || return 1
__have_cpu_feature "$feature" || return 1
done
}

Expand All @@ -28,7 +28,8 @@ make_and_test() {
# flag to get support for LIBDEFLATE_DISABLE_CPU_FEATURES.
rm -rf build
CFLAGS="$CFLAGS -DTEST_SUPPORT__DO_NOT_USE=1" \
cmake -B build -G Ninja -DLIBDEFLATE_BUILD_TESTS=1 > /dev/null
cmake -B build -G Ninja -DLIBDEFLATE_BUILD_TESTS=1 \
"${EXTRA_CMAKE_FLAGS[@]}" > /dev/null
cmake --build build > /dev/null

# Run the checksum tests, for good measure. (This isn't actually part
Expand All @@ -55,7 +56,7 @@ do_benchmark() {
__do_benchmark "$impl" "-Z"
else
__do_benchmark "libdeflate, $impl"
if [ "$ARCH" = x86_64 ]; then
if $ENABLE_32BIT; then
CFLAGS="-m32 ${EXTRA_CFLAGS[*]}" make_and_test
__do_benchmark "libdeflate, $impl, 32-bit"
fi
Expand All @@ -82,22 +83,61 @@ cleanup() {

ARCH="$(uname -m)"
USING_TMPFILE=false
EXTRA_CMAKE_FLAGS=()
ENABLE_32BIT=false

if (( $# > 1 )); then
echo "Usage: $0 [FILE]" 1>&2
trap cleanup EXIT

longopts="help"
longopts+=",cmake-flag:"
longopts+=",enable-32bit"

usage() {
echo "Usage: $0 [--cmake-flag=FLAG]... [--enable-32bit] [FILE]"
}

if ! options=$(getopt -o "" -l "$longopts" -- "$@"); then
usage 1>&2
exit 1
fi

trap cleanup EXIT
eval set -- "$options"
while (( $# >= 1 )); do
case "$1" in
--cmake-flag)
EXTRA_CMAKE_FLAGS+=("$2")
shift
;;
--enable-32bit)
ENABLE_32BIT=true
;;
--help)
usage
exit 0
;;
--)
shift
break
;;
*)
echo 1>&2 "Invalid option: '$1'"
usage 1>&2
exit 1
;;
esac
shift
done

if (( $# == 0 )); then
# Generate default test data file.
FILE=$(mktemp -t checksum_testdata.XXXXXXXXXX)
USING_TMPFILE=true
echo "Generating 100 MB test file: $FILE"
head -c 100000000 /dev/urandom > "$FILE"
else
echo "Generating 250 MB test file: $FILE"
head -c 250000000 /dev/urandom > "$FILE"
elif (( $# == 1 )); then
FILE="$1"
else
usage 1>&2
exit 1
fi

cat << EOF
Expand All @@ -115,32 +155,32 @@ case $ARCH in
i386|x86_64)
if have_cpu_features vpclmulqdq pclmulqdq avx512f avx512vl; then
do_benchmark "VPCLMULQDQ/AVX512/VL512"
disable_cpu_feature "zmm"
disable_cpu_feature zmm
do_benchmark "VPCLMULQDQ/AVX512/VL256"
disable_cpu_feature "avx512vl" "-mno-avx512vl"
disable_cpu_feature "avx512f" "-mno-avx512f"
disable_cpu_feature avx512vl "-mno-avx512vl"
disable_cpu_feature avx512f "-mno-avx512f"
fi
if have_cpu_features vpclmulqdq pclmulqdq avx2; then
do_benchmark "VPCLMULQDQ/AVX2"
disable_cpu_feature "vpclmulqdq" "-mno-vpclmulqdq"
disable_cpu_feature vpclmulqdq "-mno-vpclmulqdq"
fi
if have_cpu_features pclmulqdq avx; then
do_benchmark "PCLMULQDQ/AVX"
disable_cpu_feature "avx" "-mno-avx"
disable_cpu_feature avx "-mno-avx"
fi
if have_cpu_feature pclmulqdq; then
if have_cpu_features pclmulqdq; then
do_benchmark "PCLMULQDQ"
disable_cpu_feature "pclmulqdq" "-mno-pclmul"
disable_cpu_feature pclmulqdq "-mno-pclmul"
fi
;;
arm*|aarch*)
if have_cpu_feature crc32; then
if have_cpu_features crc32; then
do_benchmark "ARM"
disable_cpu_feature "crc32" "-march=armv8-a+nocrc"
disable_cpu_feature crc32 "-march=armv8-a+nocrc"
fi
if have_cpu_feature pmull; then
if have_cpu_features pmull; then
do_benchmark "PMULL"
disable_cpu_feature "pmull" "-march=armv8-a+nocrc+nocrypto"
disable_cpu_feature pmull "-march=armv8-a+nocrc+nocrypto"
fi
;;
esac
Expand All @@ -159,32 +199,32 @@ case $ARCH in
i386|x86_64)
if have_cpu_features avx512bw avx512_vnni; then
do_benchmark "AVX512BW/AVX512VNNI"
disable_cpu_feature "avx512_vnni" "-mno-avx512vnni"
disable_cpu_feature "avx512bw" "-mno-avx512bw"
disable_cpu_feature avx512_vnni "-mno-avx512vnni"
disable_cpu_feature avx512bw "-mno-avx512bw"
fi
if have_cpu_features avx2 avx_vnni; then
do_benchmark "AVX2/AVX-VNNI"
disable_cpu_feature "avx_vnni" "-mno-avxvnni"
disable_cpu_feature avx_vnni "-mno-avxvnni"
fi
if have_cpu_feature avx2; then
if have_cpu_features avx2; then
do_benchmark "AVX2"
disable_cpu_feature "avx2" "-mno-avx2"
disable_cpu_feature avx2 "-mno-avx2"
fi
if have_cpu_feature sse2; then
if have_cpu_features sse2; then
do_benchmark "SSE2"
disable_cpu_feature "sse2" "-mno-sse2"
disable_cpu_feature sse2 "-mno-sse2"
fi
;;
arm*)
if have_cpu_feature neon; then
if have_cpu_features neon; then
do_benchmark "NEON"
disable_cpu_feature "neon" "-mfpu=vfpv3"
disable_cpu_feature neon "-mfpu=vfpv3"
fi
;;
aarch*)
if have_cpu_feature asimd; then
if have_cpu_features asimd; then
do_benchmark "NEON"
disable_cpu_feature "neon" "-march=armv8-a+nosimd"
disable_cpu_feature neon "-march=armv8-a+nosimd"
fi
;;
esac
Expand Down

0 comments on commit 1bc5a19

Please sign in to comment.