feat(timeout): add benchmarking support with divan (#9733)

* deps: bump codspeed-divan-compat to v4.2.1

* bench(timeout): add divan benchmarks

* ci(benchmarks): include uu_timeout in codspeed list

---------

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
This commit is contained in:
mattsu
2026-04-04 22:02:21 +02:00
committed by GitHub
co-authored by Sylvestre Ledru
parent ea903d45a1
commit 79209719f9
4 changed files with 44 additions and 0 deletions
+1
View File
@@ -48,6 +48,7 @@ jobs:
uu_shuf,
uu_sort,
uu_split,
uu_timeout,
uu_tsort,
uu_unexpand,
uu_uniq,
Generated
+1
View File
@@ -4287,6 +4287,7 @@ name = "uu_timeout"
version = "0.8.0"
dependencies = [
"clap",
"codspeed-divan-compat",
"fluent",
"libc",
"nix",
+8
View File
@@ -30,3 +30,11 @@ nix = { workspace = true, features = ["signal"] }
[[bin]]
name = "timeout"
path = "src/main.rs"
[dev-dependencies]
divan = { workspace = true }
uucore = { workspace = true, features = ["benchmark"] }
[[bench]]
name = "timeout_bench"
harness = false
+34
View File
@@ -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();
}