mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:40:12 +01:00
Adds `toolchain/benchmarking/prelude_benchmark.cpp`, which measures the time to compile the Core prelude and reports the most interesting SemIR memory statistics as benchmark counters. The prelude is compiled by checking a file that imports it: the implicit prelude import causes the check phase to lex, parse, and check the full set of prelude files, so this is a direct measure of prelude compilation cost. Four input variations exercise increasing amounts of the prelude: an empty file, a minimal single-type use, an operator-heavy file that hits many impls, and a compact file that pulls in a wide swath of the prelude. Memory usage is queried directly: `Driver::set_mem_usage` takes a `MemUsage` that a compile merges each file's usage into; the benchmark passes one, compiles, and sums the entries by label. A compilation unit collects into its own `MemUsage` whenever usage is dumped or a sink is provided (decided in `SetMultiUnitCache`); after a file is done it dumps that `MemUsage` per-file as before and, if a sink was provided, merges into it via a new `MemUsage::Add(const MemUsage&)` overload. `MemUsage` also exposes its entries via a public `Entry` type and an `entries()` accessor. Also extends `scripts/bench_runner.py` to (1) treat Mem-prefixed counters as cost metrics (smaller is better) and (2) tolerate metrics that aren't reported by every benchmark in a binary. Assisted-by: Claude Code --------- Co-authored-by: Christopher Di Bella <cjdb.ns@gmail.com>