#!/bin/sh
# script/bench: run the Go benchmarks of internal/handlers, which serve
# cache hits in parallel through the image handler and report the hits
# served per second. A benchmark, not a check: script/check does not run
# it. It builds the bench phase of the Dockerfile alone, as script/test
# builds the test phase, with plain progress output so that the
# benchmark's results are shown. A new CACHEBUST value reruns the
# benchmark on every build. --output type=cacheonly writes no image.
set -eu

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"

main() {
    cd "$ROOT"
    docker build --build-arg CACHEBUST="$(date +%s)-$$" \
        --progress=plain \
        --target bench \
        --output type=cacheonly .
}

main "$@"
