diff options
author | Marvin Borner | 2023-06-17 17:04:41 +0200 |
---|---|---|
committer | Marvin Borner | 2023-06-17 17:12:03 +0200 |
commit | fb588483addb542240935b30555dedf199ff5df3 (patch) | |
tree | 6a9ef443f967a1d41f27d1410856d4f680f62024 /optim.sh | |
parent | 075378188e117b13d03b39b2f43726ab0a928d62 (diff) |
Diffstat (limited to 'optim.sh')
-rwxr-xr-x | optim.sh | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/optim.sh b/optim.sh new file mode 100755 index 0000000..04accf9 --- /dev/null +++ b/optim.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +TRIALS=100 +SUCCESSES=10 + +echo "if this takes too long, either choose a random timeout from the trials, adapt the script accordingly, or just use smaller numbers hehe" + +set -e + +make c +REFERENCE=$(./csort) + +function test() { + make asm + for i in $(seq $TRIALS); do + output=$(stdbuf -i0 -o0 -e0 ./sort) + if [ "$output" != "$REFERENCE" ]; then + return 1 + fi + done + return 0 +} + +function substitute() { + sed -ie "/^%define TIMEOUT/s/ [0-9]\+/ $1/" config.asm +} + +# TODO: Multithreading +minimum=4294967295 +successes=0 +timeout=1 +while true; do + substitute $timeout + if test; then + successes=$((successes + 1)) + echo "$successes/$SUCCESSES with $timeout" + + if [ $timeout -le $minimum ]; then + minimum=$timeout + fi + + if [ $successes -eq $SUCCESSES ]; then + break + fi + + timeout=$((timeout - timeout / 3)) + else + timeout=$((timeout * 2)) + fi +done + +substitute $minimum +echo "Done. Timeout $minimum will probably work most of the time." |