#!/bin/bash set -euo pipefail # check how fast copyparty is able to hash files during indexing # assuming an infinitely fast HDD to read from (alternatively, # checks whether you will be bottlenecked by CPU or HDD) # # uses copyparty's default config of using, well, it's complicated: # * if you have more than 8 cores, then 5 threads, # * if you have between 4 and 8, then 4 threads, # * anything less and it takes your number of cores # # can be adjusted with --hash-mt (but alpine caps out at 5) fsize=256 nfiles=128 pybin=$(command -v python3 || command -v python) #pybin=~/.pyenv/versions/nogil-3.9.10-2/bin/python3 [ $# -ge 1 ] || { echo 'need arg 1: path to copyparty-sfx.py' echo ' (remaining args will be passed on to copyparty,' echo ' for example to tweak the hasher settings)' exit 1 } sfx="$1" shift sfx="$(realpath "$sfx" || readlink -e "$sfx" || echo "$sfx")" awk=$(command -v gawk || command -v awk) uname -s | grep -E MSYS && win=1 || win= totalsize=$((fsize*nfiles)) # try to use /dev/shm to avoid hitting filesystems at all, # otherwise fallback to mktemp which probably uses /tmp td=/dev/shm/cppbenchtmp mkdir $td || td=$(mktemp -d) trap "rm -rf $td" INT TERM EXIT cd $td echo creating $fsize MiB testfile in $td sz=$((1024*1024*fsize)) head -c $sz /dev/zero | openssl enc -aes-256-ctr -iter 1 -pass pass:k -nosalt 2>/dev/null >1 || true wc -c 1 | awk '$1=='$sz'{r=1}END{exit 1-r}' || head -c $sz /dev/urandom >1 echo creating $((nfiles-1)) symlinks to it for n in $(seq 2 $nfiles); do MSYS=winsymlinks:nativestrict ln -s 1 $n; done echo warming up cache cat 1 >/dev/null echo ok lets go $pybin "$sfx" -p39204 -e2dsa --dbd=yolo --exit=idx -lo=t -q "$@" && err= || err=$? [ $win ] && [ $err = 15 ] && err= # sigterm doesn't hook on windows, ah whatever [ $err ] && echo ERROR $err && exit $err echo and the results are... LC_ALL=C $awk '/1 volumes in / {s=$(NF-1); printf "speed: %.1f MiB/s (time=%.2fs)\n", '$totalsize'/s, s}'