#!/bin/bash set -euo pipefail cd "$(dirname "$0")/.." if [[ $# -gt 2 || ${1:-main} == -* || -z ${1:-main} || ( $# -eq 2 && $2 != --core-only && $2 != --all-cases ) ]]; then printf 'Usage: %s [base-ref | BASE=base-ref] [--core-only|--all-cases]\n' "$0" >&2 exit 2 fi export SWIFT_DETERMINISTIC_HASHING=1 export PARCEL_BENCH_CORE_ONLY=1 if [[ ${2:-} == --all-cases ]]; then export PARCEL_BENCH_CORE_ONLY=0; fi base=${1:-${BASE:-main}} base=${base#BASE=} [[ -n $base && $base != -* ]] || { printf 'A base revision is required.\n' >&2; exit 2; } base_revision=$(git merge-base HEAD "$base") head_revision=$(git rev-parse HEAD) mkdir -p build/bench-ab session=$(mktemp -d "$PWD/build/bench-ab/run.XXXXXX") mkdir -p "$session/base/source" "$session/head" printf 'A/B base %s; head %s plus working-tree changes.\n' "$base_revision" "$head_revision" printf 'Instrumentation overlay: working-tree Package.swift and Tests/ParcelPerformanceTests on base production sources.\n' if [[ $PARCEL_BENCH_CORE_ONLY == 1 ]]; then printf 'Explicit common-core scope: existing 44 cases; new production-hook-dependent cases excluded from both builds.\n' else printf 'All-cases scope: both revisions must support every production benchmark hook.\n' fi git archive "$base_revision" | tar -xf - -C "$session/base/source" rm -rf "$session/base/source/Tests/ParcelPerformanceTests" cp -R Tests/ParcelPerformanceTests "$session/base/source/Tests/ParcelPerformanceTests" cp Package.swift "$session/base/source/Package.swift" # The manifest's developer targets must accompany the harness overlay, not alter production sources. for target in Sources/ParcelDev Sources/parcel-dev Tests/ParcelDevTests; do if [[ -d $target ]]; then rm -rf "$session/base/source/$target" cp -R "$target" "$session/base/source/$target" fi done # Both binaries are built before any reading; base production sources stay at the merge base. swift build --package-path "$session/base/source" --scratch-path "$session/base/build" -c release --build-tests -Xswiftc -enable-testing swift build --package-path "$PWD" --scratch-path "$session/head/build" -c release --build-tests -Xswiftc -enable-testing args=(--output "${BENCH_AB_OUTPUT:-build/bench-ab/summary.json}" --base-revision "$base_revision" --head-revision "$head_revision") for round in 1 2 3 4 5; do for variant in base head; do source=$PWD [[ $variant != base ]] || source="$session/base/source" output="$session/$variant/round-$round.json" printf 'A/B round %s/5: %s\n' "$round" "$variant" PARCEL_BENCH=1 PARCEL_BENCH_NO_COMPARE=1 PARCEL_BENCH_RECORD=0 PARCEL_BENCH_OUTPUT="$output" \ swift test --package-path "$source" --scratch-path "$session/$variant/build" \ -c release --skip-build -Xswiftc -enable-testing --no-parallel --filter PerformanceBenchmarks [[ -s $output ]] || { printf 'Benchmark runner did not write %s\n' "$output" >&2; exit 2; } args+=("--$variant" "$output") done done Scripts/parcel-dev.sh bench-ab-summary "${args[@]}"