mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
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:
co-authored by
Sylvestre Ledru
parent
ea903d45a1
commit
79209719f9
@@ -48,6 +48,7 @@ jobs:
|
||||
uu_shuf,
|
||||
uu_sort,
|
||||
uu_split,
|
||||
uu_timeout,
|
||||
uu_tsort,
|
||||
uu_unexpand,
|
||||
uu_uniq,
|
||||
|
||||
Generated
+1
@@ -4287,6 +4287,7 @@ name = "uu_timeout"
|
||||
version = "0.8.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"codspeed-divan-compat",
|
||||
"fluent",
|
||||
"libc",
|
||||
"nix",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user