Luigit
repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by admin

smith-bench/benches/startup.rs

Raw
//! Instruction budgets of process start-up (`SMH-SPEC-SPEC0001`,
//! Performance and portability: help within 100 ms): the release binary
//! under callgrind, pinned in `smith-bench/budgets.toml` and gated by
//! `cargo x perf`.
//!
//! Start-up is the measurement here, so the whole process counts. The
//! binary comes from `SMITH_BIN`, which `cargo x perf` builds and sets.
//! Every run gets fresh, empty XDG roots and, gungraun clearing the
//! environment, no provider variable: the e2e tests' isolation. The
//! clearing keeps `LD_LIBRARY_PATH`, which `cargo run` (so `cargo x`)
//! extends; the dynamic loader walks every entry, so it is emptied to
//! keep start-up counts independent of how the bench was launched.

#![expect(
    missing_docs,
    reason = "gungraun benchmark macros generate undocumented public modules and items"
)]

use gungraun::Callgrind;
use gungraun::prelude::*;
use std::path::{Path, PathBuf};

/// Profile root of every run, under cargo's per-target scratch directory.
fn home() -> PathBuf {
    Path::new(env!("CARGO_TARGET_TMPDIR")).join("smith-bench-home")
}

/// An empty profile, so no run sees what an earlier one left behind.
fn fresh_home() {
    let home = home();
    let _ = std::fs::remove_dir_all(&home);
    std::fs::create_dir_all(&home).expect("profile root");
}

#[binary_benchmark(setup = fresh_home())]
#[bench::help(&["--help"])]
#[bench::eval_mock(&["eval", "--mock", "hello"])]
fn smith(args: &[&str]) -> gungraun::Command {
    let binary = std::env::var("SMITH_BIN")
        .expect("SMITH_BIN names the release smith binary; run `cargo x perf`");
    let home = home();
    gungraun::Command::new(binary)
        .args(args)
        .env("XDG_CONFIG_HOME", home.join("config"))
        .env("XDG_DATA_HOME", home.join("data"))
        .env("XDG_STATE_HOME", home.join("state"))
        .env("XDG_CACHE_HOME", home.join("cache"))
        .env("LD_LIBRARY_PATH", "")
        .build()
}

binary_benchmark_group!(name = cli, benchmarks = smith);

main!(
    config = BinaryBenchmarkConfig::default().tool(Callgrind::with_args(["--cache-sim=no"])),
    binary_benchmark_groups = cli
);