#[bench]Expand description
#[gpui::bench] annotates a Criterion benchmark that runs with GPUI support.
Use #[gpui::bench(inputs = some_iterable())] on benchmarks that take an
additional input argument; the generated benchmark uses Criterion’s
bench_with_input. group, input_name, and sample_size can customize
the generated input benchmark group.
A benchmark that takes a StdRng parameter (by value, in any position) is run
once per seed, with the RNG seeded from it. Seeds are chosen exactly as for
#[gpui::test]: seed = N, seeds(...), and iterations = N take the same
meaning, and the SEED and ITERATIONS environment variables override them the
same way, so one SEED reproduces a test or a benchmark. Each seed is its own
Criterion benchmark, named <input>/seed-<seed> (or <function>/seed-<seed>
without inputs), and the RNG is rebuilt for every Criterion routine call so all
samples measure the same seed. The generated code seeds it through gpui’s own
rand, so the crate needs rand only to name StdRng in the signature.
#[gpui::bench(inputs = families(), iterations = 6)]
fn full_refresh(family: &Family, mut rng: StdRng, cx: &mut BenchAppContext) {
let tree = family.sample(&mut rng);
// ...
}The benchmark crate must add criterion and gpui_platform (with its
test-support feature) to its dev-dependencies and enable gpui’s bench
feature, since the generated code references all three.