-
-
Save ppigazzini/bbbb90fec386c16a13174b1cc20a44d9 to your computer and use it in GitHub Desktop.
bench in parallel subshelles two builds of stockfish
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
_bench () { | |
${1} << EOF > /dev/null 2>> ${2} | |
bench 16 1 ${depth} default depth | |
EOF | |
} | |
# the _bench function customization example | |
# setoption name SyzygyPath value C:\tablebases\wdl345;C:\tablebases\dtz345 | |
# bench 128 4 ${depth} default depth | |
if [[ ${#} -ne 4 ]]; then | |
cat << EOF | |
usage: ${0} base test depth n_runs | |
fast test: | |
${0} ./stockfish_base ./stockfish_test 13 10 | |
slow test: | |
${0} ./stockfish_base ./stockfish_test 20 10 | |
EOF | |
exit 1 | |
fi | |
base=${1} | |
test=${2} | |
depth=${3} | |
n_runs=${4} | |
# preload of CPU/cache/memory | |
(_bench ${base} base000.txt)& | |
(_bench ${test} test000.txt)& | |
wait | |
# temporary files initialization | |
cat /dev/null > base000.txt | |
cat /dev/null > test000.txt | |
cat /dev/null > tmp000.txt | |
# bench loop: SMP bench with background subshells | |
for ((k=1; k<=${n_runs}; k++)); do | |
printf "run %3d /%3d\n" ${k} ${n_runs} | |
# swap the execution order to avoid bias | |
if [ $((k%2)) -eq 0 ]; then | |
(_bench ${base} base000.txt)& | |
(_bench ${test} test000.txt)& | |
wait | |
else | |
(_bench ${test} test000.txt)& | |
(_bench ${base} base000.txt)& | |
wait | |
fi | |
done | |
# text processing to extract nps values | |
cat base000.txt | grep second | grep -Eo '[0-9]{1,}' > base001.txt | |
cat test000.txt | grep second | grep -Eo '[0-9]{1,}' > test001.txt | |
for ((k=1; k<=${n_runs}; k++)); do | |
echo ${k} >> tmp000.txt | |
done | |
printf "\nrun\tbase\ttest\tdiff\n" | |
paste tmp000.txt base001.txt test001.txt | awk '{printf "%3d %d %d %+d\n", $1, $2, $3, $3-$2}' | |
paste base001.txt test001.txt | awk '{printf "%d\t%d\t%d\n", $1, $2, $2-$1}' > tmp000.txt | |
# compute: sample mean, 1.96 * std of sample mean (95% of samples), speedup | |
# std of sample mean = sqrt(NR/(NR-1)) * (std population) / sqrt(NR) | |
cat tmp000.txt | awk '{sum1 += $1 ; sumq1 += $1**2 ;sum2 += $2 ; sumq2 += $2**2 ;sum3 += $3 ; sumq3 += $3**2 } END {printf "\nbase = %10d +/- %d\ntest = %10d +/- %d\ndiff = %10d +/- %d\nspeedup = %.6f\n\n", sum1/NR , 1.96 * sqrt(sumq1/NR - (sum1/NR)**2)/sqrt(NR-1) , sum2/NR , 1.96 * sqrt(sumq2/NR - (sum2/NR)**2)/sqrt(NR-1) , sum3/NR , 1.96 * sqrt(sumq3/NR - (sum3/NR)**2)/sqrt(NR-1) , (sum2 - sum1)/sum1 }' | |
# remove temporary files | |
rm -f base000.txt test000.txt tmp000.txt base001.txt test001.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment