Files
indivisible-rs/benchmark.sh

46 lines
755 B
Bash
Raw Normal View History

2025-12-05 15:50:38 +01:00
#!/bin/bash
EXE="./target/release/indivisible"
OPTIONS=()
2025-12-05 16:15:44 +01:00
TRIALS=20
2025-12-05 15:50:38 +01:00
if ! [ -f "$EXE" ]
2025-12-05 15:50:38 +01:00
then
>&2 echo "Release build not available. Please run 'cargo build -r'."
exit 1
fi
2025-12-06 17:47:42 +01:00
if ! command -v calc &>/dev/null
then
>&2 echo "Missing 'calc' program. Please install it for this script."
exit 1
fi
while getopts "t:s:" opt
do
case "$opt" in
s)
OPTIONS=("${OPTIONS[@]}" -s "$OPTARG")
;;
t)
TRIALS="$OPTARG"
;;
*)
>&2 echo "Uknown option $opt"
exit 1
;;
esac
done
2025-12-10 14:59:33 +01:00
echo "Calculating primes up to 1,000,000,000"
2025-12-05 16:15:44 +01:00
TOTAL="0"
for _ in $(seq "$TRIALS")
do
2025-12-10 14:59:33 +01:00
TIME=$(command time -f "%e" "$EXE" "${OPTIONS[@]}" 1000000000 2>&1 >/dev/null)
2025-12-05 16:15:44 +01:00
TOTAL=$(calc "$TOTAL + $TIME")
done
AVG=$(calc "$TOTAL / $TRIALS")
echo "Average time: ${AVG}s"