tools/checksum_benchmarks.sh: various improvements

Make it compatible with the new code organization, make it run the
test_checksums program for each implementation, and run each
implementation in both 64-bit and 32-bit modes.
This commit is contained in:
Eric Biggers 2018-02-18 23:03:26 -08:00
parent bf0797e666
commit e7aa4666e0

View File

@ -4,6 +4,9 @@ set -eu
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
FILE="$HOME/data/silesia" FILE="$HOME/data/silesia"
[ ! -e "$FILE" ] && FILE="$HOME/silesia"
[ ! -e "$FILE" ] && FILE="$HOME/data/testdata"
[ ! -e "$FILE" ] && FILE="$HOME/testdata"
echo "Using default FILE: $FILE" echo "Using default FILE: $FILE"
echo echo
elif [ $# -eq 1 ]; then elif [ $# -eq 1 ]; then
@ -13,64 +16,126 @@ else
exit 1 exit 1
fi fi
ARCH="$(uname -m)"
if ! grep -q '\<sse2\>' /proc/cpuinfo; then if [ -n "$(git status -s | egrep 'adler32_impl.h|crc32_impl.h')" ]; then
echo "This script must be run on an x86 CPU" 1>&2 echo "This script will overwrite adler32_impl.h and crc32_impl.h," \
"which have uncommitted changes. Refusing to run." 1>&2
exit 1 exit 1
fi fi
if [ -n "$(git status -s | egrep 'adler32.c|crc32.c')" ]; then have_cpu_feature() {
echo "This script will overwrite adler32.c and crc32.c, which" \ local feature="$1"
"have uncommitted changes. Refusing to run." 1>&2 local tag
exit 1 case $ARCH in
fi arm*|aarch*)
tag="Features"
;;
*)
tag="flags"
;;
esac
grep -q "^$tag"$'[ \t]'"*:.*\<$feature\>" /proc/cpuinfo
}
make_and_test() {
make "$@" checksum test_checksums > /dev/null
./test_checksums > /dev/null
}
__do_benchmark() {
local impl="$1" speed
shift
local flags="$CKSUM_FLAGS $*"
speed=$(./checksum $flags -t "$FILE" | \
grep -o '[0-9]\+ MB/s' | grep -o '[0-9]\+')
printf "%-45s%-10s\n" "$CKSUM_NAME ($impl)" "$speed"
}
do_benchmark() { do_benchmark() {
method="$1" local impl="$1"
shift
speed=$(./checksum "$@" -t "$FILE" | \ if [ "$impl" = zlib ]; then
grep -o '[0-9]\+ MB/s' | grep -o '[0-9]\+') __do_benchmark "$impl" "-Z"
printf "%-36s%-10s\n" "$method" "$speed" else
make_and_test CFLAGS="$EXTRA_CFLAGS"
__do_benchmark "libdeflate, $impl"
if [ $ARCH = x86_64 ]; then
make_and_test CFLAGS="-m32 $EXTRA_CFLAGS"
__do_benchmark "libdeflate, $impl, 32-bit"
fi
fi
} }
sort_by_speed() { sort_by_speed() {
awk '{print $NF, $0}' | sort -nr | cut -f2- -d' ' awk '{print $NF, $0}' | sort -nr | cut -f2- -d' '
} }
disable_impl() {
local name="$1"
local extra_cflags="$2"
sed -i '/^\#ifdef DISPATCH_'"$name"'$/aif (0)' lib/*/{adler,crc}32_impl.h
EXTRA_CFLAGS+=" $extra_cflags"
}
restore_impls() {
git checkout -f lib/*/{adler,crc}32_impl.h
}
trap restore_impls EXIT
cat << EOF cat << EOF
Method Speed (MB/s) Method Speed (MB/s)
------ ------------ ------ ------------
EOF EOF
# CRC-32 # CRC-32
( CKSUM_NAME="CRC-32"
if grep -q '\<pclmulqdq\>' /proc/cpuinfo; then CKSUM_FLAGS=""
make checksum > /dev/null EXTRA_CFLAGS=""
do_benchmark "CRC-32 (libdeflate, PCLMUL/AVX)" {
sed -i '/^\#if NEED_PCLMUL_IMPL && !defined(__AVX__)/,/^\#endif$/d' lib/crc32.c case $ARCH in
make checksum > /dev/null i386|x86_64)
do_benchmark "CRC-32 (libdeflate, PCLMUL)" if have_cpu_feature pclmulqdq && have_cpu_feature avx; then
fi do_benchmark "PCLMUL/AVX"
sed -i '/^#if defined(__PCLMUL__)/,/^\#endif$/d' lib/crc32.c disable_impl "PCLMUL_AVX" "-mno-avx"
make checksum > /dev/null fi
do_benchmark "CRC-32 (libdeflate, generic)" if have_cpu_feature pclmulqdq; then
git checkout -f lib/crc32.c > /dev/null do_benchmark "PCLMUL"
do_benchmark "CRC-32 (zlib)" -Z disable_impl "PCLMUL" "-mno-pclmul"
) | sort_by_speed fi
;;
esac
do_benchmark "generic"
do_benchmark "zlib"
} | sort_by_speed
# Adler-32 # Adler-32
CKSUM_NAME="Adler-32"
CKSUM_FLAGS="-A"
EXTRA_CFLAGS=""
echo echo
( {
if grep -q '\<avx2\>' /proc/cpuinfo; then case $ARCH in
make checksum > /dev/null i386|x86_64)
do_benchmark "Adler-32 (libdeflate, AVX2)" -A if have_cpu_feature avx2; then
fi do_benchmark "AVX2"
sed -i '/^#if defined(__AVX2__)/,/^\#endif$/d' lib/adler32.c disable_impl "AVX2" "-mno-avx2"
make checksum > /dev/null fi
do_benchmark "Adler-32 (libdeflate, SSE2)" -A if have_cpu_feature sse2; then
sed -i '/^#ifdef __SSE2__/,/^\#endif$/d' lib/adler32.c do_benchmark "SSE2"
make checksum > /dev/null disable_impl "SSE2" "-mno-sse2"
do_benchmark "Adler-32 (libdeflate, generic)" -A fi
git checkout -f lib/adler32.c > /dev/null ;;
do_benchmark "Adler-32 (zlib)" -A -Z arm*|aarch*)
) | sort_by_speed if have_cpu_feature neon; then
do_benchmark "NEON"
disable_impl "NEON" "-mfpu=vfpv3"
fi
;;
esac
do_benchmark "generic"
do_benchmark "zlib"
} | sort_by_speed