Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
Shell
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394#!/usr/bin/env bash# Batch-vs-separate candidate compilation benchmark: for each N, generates both a# one-crate-N-function layout and an N-separate-crate workspace (gen_candidates.py under# bench/gen/, gitignored), then measures `cargo check` and `cargo build --release`# wall-clock and CPU-seconds for each layout, uncached versus through sccache. Also runs# `dedup_cost` against the batch layout's source. Prints one JSON line per# (N, layout, command, cache-state).## The two `cache_state` values are "uncached" (RUSTC_WRAPPER explicitly unset with# `env -u`, so every object is compiled from scratch: the worst case, e.g. a machine with# no sccache configured -- this box's shell profile exports RUSTC_WRAPPER=sccache for# every cargo invocation by default, so merely not setting it is not enough) and# "sccache" (RUSTC_WRAPPER=sccache, going through whatever persistent sccache server is# already running on the box). There is no isolated cold-cache measurement: sccache's# server, once started, keeps the disk-cache directory it was launched with regardless of# a client's `SCCACHE_DIR`, and stopping the box's shared server to force a clean one# would disrupt other tracks' builds that route through it. "sccache" therefore reflects# steady-state operation once the fleet's cache is warm, not a from-empty first build.## Usage: bench/compile-batch.sh [N ...] # defaults to 10 100 1000set -euo pipefail
BENCH_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"GEN_DIR="$BENCH_DIR/gen"export CARGO_TARGET_DIR="$BENCH_DIR/target"
Ns=("$@")if [ ${#Ns[@]} -eq 0 ]; then Ns=(10 100 1000)fi
cargo build --release --manifest-path "$BENCH_DIR/Cargo.toml" --bin dedup_cost >/dev/null
mkdir -p "$GEN_DIR"
# Runs `cargo check` or `cargo build --release` (selected by `label`, "check" or# "build-release") against `<manifest>`, using a scratch target dir so neither pass# benefits from cargo's own incremental cache, and prints one JSON line.measure() { local layout="$1" n="$2" label="$3" cache_state="$4" manifest="$5" local cargo_args case "$label" in check) cargo_args=(check) ;; build-release) cargo_args=(build --release) ;; *) echo "unknown label: $label" >&2; exit 1 ;; esac local scratch_target scratch_target="$(mktemp -d)" local timing timing="$(mktemp)" echo "load before $layout N=$n $label ($cache_state): $(uptime)" >&2 # This box's shell profile exports RUSTC_WRAPPER=sccache for every cargo invocation, so # "uncached" must explicitly unset it (`env -u`) rather than merely not setting it. if [ "$cache_state" = "sccache" ]; then env RUSTC_WRAPPER=sccache CARGO_TARGET_DIR="$scratch_target" \ /usr/bin/time -f '%e %S %U' -o "$timing" \ cargo "${cargo_args[@]}" --manifest-path "$manifest" --quiet else env -u RUSTC_WRAPPER CARGO_TARGET_DIR="$scratch_target" \ /usr/bin/time -f '%e %S %U' -o "$timing" \ cargo "${cargo_args[@]}" --manifest-path "$manifest" --quiet fi read -r wall sys user < "$timing" rm -rf "$scratch_target" "$timing" python3 -c "import jsonprint(json.dumps({ 'layout': '$layout', 'n': $n, 'subcommand': '$label', 'cache_state': '$cache_state', 'wall_s': $wall, 'cpu_s': $sys + $user,}))"}
for n in "${Ns[@]}"; do python3 "$BENCH_DIR/gen_candidates.py" "$GEN_DIR" "$n" batch python3 "$BENCH_DIR/gen_candidates.py" "$GEN_DIR" "$n" separate
batch_manifest="$GEN_DIR/batch_$n/Cargo.toml" separate_manifest="$GEN_DIR/separate_$n/Cargo.toml"
measure batch "$n" check uncached "$batch_manifest" measure batch "$n" build-release uncached "$batch_manifest" measure separate "$n" check uncached "$separate_manifest" measure separate "$n" build-release uncached "$separate_manifest"
measure batch "$n" check sccache "$batch_manifest" measure batch "$n" build-release sccache "$batch_manifest" measure separate "$n" check sccache "$separate_manifest" measure separate "$n" build-release sccache "$separate_manifest"
dedup_cost_bin="$CARGO_TARGET_DIR/release/dedup_cost" "$dedup_cost_bin" --file "$GEN_DIR/batch_$n/src/lib.rs"done