Skip to content

Commit d24bf80

Browse files
authored
feat(true/false): add benchmarks for startup performance (#10996)
* feat(true/false): add benchmarks for startup performance Add benchmarks to evaluate true/false command performance, addressing GitHub issue #10837. Benchmarks include: - Function call benchmarks (measure uumain directly) * true_no_args, true_help, true_version, true_consecutive_calls - Process spawn benchmarks (measure real command startup) * true_spawn_no_args, true_spawn_help, true_spawn_version This allows comparison between hot path vs cold path performance and internal logic vs real-world startup time. * chore(true/false): reduce benchmarks to 2 essential cases --------- Co-authored-by: naoNao89 <naoNao89@users.noreply.github.com>
1 parent 995c6dc commit d24bf80

6 files changed

Lines changed: 81 additions & 1 deletion

File tree

.github/workflows/benchmarks.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ jobs:
5353
uu_wc,
5454
uu_factor,
5555
uu_date,
56-
uu_csplit
56+
uu_csplit,
57+
uu_true,
58+
uu_false
5759
]
5860
steps:
5961
- uses: actions/checkout@v6

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uu/false/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,11 @@ fluent = { workspace = true }
2727
[[bin]]
2828
name = "false"
2929
path = "src/main.rs"
30+
31+
[dev-dependencies]
32+
divan = { workspace = true }
33+
uucore = { workspace = true, features = ["benchmark"] }
34+
35+
[[bench]]
36+
name = "false_bench"
37+
harness = false
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// This file is part of the uutils coreutils package.
2+
//
3+
// For the full copyright and license information, please view the LICENSE
4+
// file that was distributed with this source code.
5+
6+
use divan::{Bencher, black_box};
7+
use uu_false::uumain;
8+
use uucore::benchmark::run_util_function;
9+
10+
/// Benchmark the common case: false with no arguments
11+
#[divan::bench]
12+
fn false_no_args(bencher: Bencher) {
13+
bencher.bench(|| {
14+
black_box(run_util_function(uumain, &[]));
15+
});
16+
}
17+
18+
/// Benchmark multiple consecutive invocations (throughput test)
19+
#[divan::bench]
20+
fn false_consecutive_calls(bencher: Bencher) {
21+
bencher.bench(|| {
22+
for _ in 0..100 {
23+
black_box(run_util_function(uumain, &[]));
24+
}
25+
});
26+
}
27+
28+
fn main() {
29+
divan::main();
30+
}

src/uu/true/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,11 @@ fluent = { workspace = true }
2626
[[bin]]
2727
name = "true"
2828
path = "src/main.rs"
29+
30+
[dev-dependencies]
31+
divan = { workspace = true }
32+
uucore = { workspace = true, features = ["benchmark"] }
33+
34+
[[bench]]
35+
name = "true_bench"
36+
harness = false

src/uu/true/benches/true_bench.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// This file is part of the uutils coreutils package.
2+
//
3+
// For the full copyright and license information, please view the LICENSE
4+
// file that was distributed with this source code.
5+
6+
use divan::{Bencher, black_box};
7+
use uu_true::uumain;
8+
use uucore::benchmark::run_util_function;
9+
10+
/// Benchmark the common case: true with no arguments
11+
#[divan::bench]
12+
fn true_no_args(bencher: Bencher) {
13+
bencher.bench(|| {
14+
black_box(run_util_function(uumain, &[]));
15+
});
16+
}
17+
18+
/// Benchmark multiple consecutive invocations (throughput test)
19+
#[divan::bench]
20+
fn true_consecutive_calls(bencher: Bencher) {
21+
bencher.bench(|| {
22+
for _ in 0..100 {
23+
black_box(run_util_function(uumain, &[]));
24+
}
25+
});
26+
}
27+
28+
fn main() {
29+
divan::main();
30+
}

0 commit comments

Comments
 (0)