diff options
author | cos <cos> | 2020-12-01 22:36:49 +0100 |
---|---|---|
committer | cos <cos> | 2020-12-01 23:47:05 +0100 |
commit | b2087ba800937e357a94ff7491cefae15e5198ef (patch) | |
tree | f5e5e6f38f0f211341d9d94a7234921ec2d0e5a5 /bin/measure_time.sh | |
parent | f44158d941198d175c26ef8f74e80e4d4d0fa7a2 (diff) | |
download | adventofcode-b2087ba800937e357a94ff7491cefae15e5198ef.zip |
Add code to measure time and memory consumption
Diffstat (limited to 'bin/measure_time.sh')
-rwxr-xr-x | bin/measure_time.sh | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/bin/measure_time.sh b/bin/measure_time.sh new file mode 100755 index 0000000..d308b19 --- /dev/null +++ b/bin/measure_time.sh @@ -0,0 +1,40 @@ +#!/bin/sh -e + +YEAR="${YEAR:-$(date +%Y)}" +DAY="${DAY:-$(TZ=EST date '+%d')}" +IMPL="${IMPL:-rust}" +PARTS="${AOC_PARTS:-1 2}" + +ITERS="${ITERS:-10}" + +cd "${YEAR}/${IMPL}/day${DAY}" +case "${IMPL}" in + 'rust') + cargo build --release + EXECUTABLE="../target/release/day${DAY}" + ;; + *) + echo "Unknown implementation: ${IMPL}" >&2 + exit + ;; +esac + +for PART in $(echo ${PARTS}) +do + export AOC_PARTS="${PART}" + OUT="time-${YEAR}-${IMPL}-${DAY}-${PART}.txt" + + export TIMEFMT='%uE' + for I in $(seq "${ITERS}"); do + zsh -c time "${EXECUTABLE}" "${@}" 2>&1 >/dev/null | tail -1 + done >"${OUT}" + + ALL_TIMINGS="$(cat "${OUT}" | sed 's/us/ + /' )" + NO_OF_ITERS=$(echo "${ALL_TIMINGS}" | wc -l) + ARITHM="$(echo "( ${ALL_TIMINGS}" | tr -d '\n'; \ + echo "0 ) / ${NO_OF_ITERS}" )" + MEAN_TIMING=$(( $(echo ${ARITHM}) )) + + printf "${YEAR}-${IMPL}-${DAY}-${PART}: Mean: ${MEAN_TIMING}µs\n" + printf "${YEAR}-${IMPL}-${DAY}-${PART}: Mean: ${MEAN_TIMING}µs\n" >>"${OUT}" +done |