diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index ec97e294e69..c464eea99d0 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -1,6 +1,6 @@ name: Benchmarks -# spell-checker:ignore codspeed dtolnay Swatinem sccache +# spell-checker:ignore codspeed dtolnay Swatinem sccache memtrack moonrepo on: pull_request: @@ -43,6 +43,7 @@ jobs: uu_shuf, uu_sort, uu_split, + uu_timeout, uu_tsort, uu_unexpand, uu_uniq, @@ -55,16 +56,15 @@ jobs: with: persist-credentials: false - - uses: dtolnay/rust-toolchain@stable - - - uses: Swatinem/rust-cache@v2 - - - name: Run sccache-cache - uses: mozilla-actions/sccache-action@v0.0.9 - - - name: Install cargo-codspeed - shell: bash - run: cargo install cargo-codspeed --locked + # Prefer CodSpeed's recommended setup to keep toolchain/binary versions aligned + # with the CodSpeed action (helps avoid memtrack/cargo-codspeed incompatibilities). + - name: Setup Rust (with cargo-codspeed) + uses: moonrepo/setup-rust@v1 + with: + channel: 1.85.0 + cache: true + cache-target: true + bins: cargo-codspeed - name: Build benchmarks for ${{ matrix.package }} (${{ matrix.type }}) shell: bash @@ -80,6 +80,7 @@ jobs: uses: CodSpeedHQ/action@v4 env: CODSPEED_LOG: debug + RUST_BACKTRACE: full with: mode: ${{ matrix.type == 'memory' && 'memory' || 'simulation' }} run: | diff --git a/Cargo.lock b/Cargo.lock index 5cfe22c15d1..1f598f66b54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3990,6 +3990,7 @@ name = "uu_timeout" version = "0.5.0" dependencies = [ "clap", + "codspeed-divan-compat", "fluent", "libc", "nix", diff --git a/Cargo.toml b/Cargo.toml index 77738518f97..2d831f06a59 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -318,7 +318,7 @@ compare = "0.1.0" crossterm = "0.29.0" ctor = "0.6.0" ctrlc = { version = "3.4.7", features = ["termination"] } -divan = { package = "codspeed-divan-compat", version = "4.0.5" } +divan = { package = "codspeed-divan-compat", version = "4.2.1" } dns-lookup = { version = "3.0.0" } exacl = "0.12.0" file_diff = "1.0.0" diff --git a/src/uu/timeout/Cargo.toml b/src/uu/timeout/Cargo.toml index c6b795628f7..cb87a6b70e9 100644 --- a/src/uu/timeout/Cargo.toml +++ b/src/uu/timeout/Cargo.toml @@ -27,3 +27,11 @@ fluent = { workspace = true } [[bin]] name = "timeout" path = "src/main.rs" + +[dev-dependencies] +divan = { workspace = true } +uucore = { workspace = true, features = ["benchmark"] } + +[[bench]] +name = "timeout_bench" +harness = false diff --git a/src/uu/timeout/benches/timeout_bench.rs b/src/uu/timeout/benches/timeout_bench.rs new file mode 100644 index 00000000000..511955f6f0b --- /dev/null +++ b/src/uu/timeout/benches/timeout_bench.rs @@ -0,0 +1,34 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + +#[cfg(unix)] +use divan::{Bencher, black_box}; +#[cfg(unix)] +use uu_timeout::uumain; +#[cfg(unix)] +use uucore::benchmark::run_util_function; + +/// Benchmark the fast path where the command exits immediately. +#[cfg(unix)] +#[divan::bench] +fn timeout_quick_exit(bencher: Bencher) { + bencher.bench(|| { + black_box(run_util_function(uumain, &["0.02", "true"])); + }); +} + +/// Benchmark a command that runs longer than the threshold and receives the default signal. +#[cfg(unix)] +#[divan::bench] +fn timeout_enforced(bencher: Bencher) { + bencher.bench(|| { + black_box(run_util_function(uumain, &["0.02", "sleep", "0.2"])); + }); +} + +fn main() { + #[cfg(unix)] + divan::main(); +}