Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
uu_shuf,
uu_sort,
uu_split,
uu_timeout,
uu_tsort,
uu_unexpand,
uu_uniq,
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/uu/timeout/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 34 additions & 0 deletions src/uu/timeout/benches/timeout_bench.rs
Original file line number Diff line number Diff line change
@@ -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();
}
Loading