Skip to content
Open
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
3 changes: 2 additions & 1 deletion .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ jobs:
- { package: uu_shuf }
- { package: uu_sort }
- { package: uu_split }
- { package: uu_tsort }
- { package: uu_timeout }
- { package: uu_tsort }
- { package: uu_unexpand }
- { package: uu_uniq }
- { package: uu_wc }
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 @@ -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
37 changes: 37 additions & 0 deletions src/uu/timeout/benches/timeout_bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// This file is part of the uutils coreutils package.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't the right way to call the benchmark.
we should call the rust function (see others)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix

//
// 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;

#[cfg(unix)]
fn bench_timeout(bencher: Bencher, args: &[&str]) {
bencher.bench(|| {
black_box(run_util_function(uumain, args));
});
}

/// Benchmark the fast path where the command exits immediately.
#[cfg(unix)]
#[divan::bench]
fn timeout_quick_exit(bencher: Bencher) {
bench_timeout(bencher, &["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) {
bench_timeout(bencher, &["0.02", "sleep", "0.2"]);
}

fn main() {
#[cfg(unix)]
divan::main();
}
Loading