summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbench50
-rwxr-xr-xcheck16
2 files changed, 11 insertions, 55 deletions
diff --git a/bench b/bench
deleted file mode 100755
index 8cdc95d..0000000
--- a/bench
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/usr/bin/env sh
-
-usage="usage: bench <year> <day> <language> <testfile> [<warmups>]"
-year=${1?$usage}
-day=${2?$usage}
-lang=${3?$usage}
-input=${4?$usage}
-warmups=${5:-0}
-
-# get directory of this script
-script=$(readlink -f "$0")
-script_path=$(dirname "$script")
-
-# find aoc and data paths
-aoc_path=$script_path/$year/$day
-data_path="$aoc_path/data/$input.txt"
-
-# check solution is correct for this input
-$script_path/check $year $day $lang $input >/dev/null
-[ ! $? ] && echo "incorrect solution" && exit 1
-
-case $lang in
-"python")
- # Sync to create venv
- uv sync \
- --directory \
- $aoc_path/python
- # Bypass any `uv run` overhead and run .venv directly
- exec="$aoc_path/python/.venv/bin/python $aoc_path/python/main.py"
- ;;
-"rust")
- # Compile to /tmp/aoc_rust and run binary
- cargo build \
- --release \
- --target-dir /tmp/aoc_rust \
- --manifest-path \
- $aoc_path/rust/Cargo.toml
- exec="/tmp/aoc_rust/release/aoc_$year-$day"
- ;;
-*)
- echo "unknown lang: $lang"
- exit 1
- ;;
-esac
-
-hyperfine \
- --shell none \
- --warmup $warmups \
- --input $data_path \
- "$exec"
diff --git a/check b/check
index d62364e..174c7af 100755
--- a/check
+++ b/check
@@ -1,10 +1,11 @@
#!/usr/bin/env sh
-usage="usage: check <year> <day> <language> <testfile>"
+usage="usage: check <year> <day> <language> <testfile> [<benchmark>]"
year=${1?$usage}
day=${2?$usage}
lang=${3?$usage}
input=${4?$usage}
+bench=$5
# get directory of this script
script=$(readlink -f "$0")
@@ -16,13 +17,15 @@ data_path="$aoc_path/data/$input.txt"
case $lang in
"python")
- cmd="uv run --directory $aoc_path/python main.py"
+ solve="$aoc_path/python.py"
;;
"rust")
- cmd="cargo run --manifest-path $aoc_path/rust/Cargo.toml --"
+ cargo build --target-dir /tmp/aoc_rust --manifest-path $aoc_path/rust/Cargo.toml
+ solve="/tmp/aoc_rust/debug/aoc_$year-$day"
;;
"rustc")
- cmd="cargo run --release --manifest-path $aoc_path/rust/Cargo.toml --"
+ cargo build --release --target-dir /tmp/aoc_rust --manifest-path $aoc_path/rust/Cargo.toml
+ solve="/tmp/aoc_rust/release/aoc_$year-$day"
;;
"*")
echo "unknown lang: $lang"
@@ -30,11 +33,14 @@ case $lang in
;;
esac
-result=$(cat $data_path | $cmd)
+result=$(cat $data_path | $solve)
diff=$(echo "$result" | diff $aoc_path/data/$4.ans -)
code=$?
[ $code -eq 0 ] && echo Solved with $lang! || echo "$diff"
+
+[ -n "$bench" ] && hyperfine --shell none --input $data_path "$solve" && exit 0
+
echo "\n---stdout---"
echo "$result"
exit $code