Skip to content

Commit 8db2277

Browse files
authored
echo: add benchmark (#12091)
1 parent 454832b commit 8db2277

4 files changed

Lines changed: 32 additions & 0 deletions

File tree

.github/workflows/benchmarks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
uu_dd,
3737
uu_df,
3838
uu_du,
39+
uu_echo,
3940
uu_expand,
4041
uu_fold,
4142
uu_hostname,

Cargo.lock

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

src/uu/echo/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 = "echo"
2929
path = "src/main.rs"
30+
31+
[dev-dependencies]
32+
divan = { workspace = true }
33+
uucore = { workspace = true, features = ["benchmark"] }
34+
35+
[[bench]]
36+
name = "echo_bench"
37+
harness = false

src/uu/echo/benches/echo_bench.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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_echo::uumain;
8+
use uucore::benchmark::run_util_function;
9+
10+
/// Benchmark multiple consecutive invocations
11+
#[divan::bench]
12+
fn echo_consecutive_calls(bencher: Bencher) {
13+
bencher.bench(|| {
14+
for _ in 0..100 {
15+
black_box(run_util_function(uumain, &["Hello World"]));
16+
}
17+
});
18+
}
19+
20+
fn main() {
21+
divan::main();
22+
}

0 commit comments

Comments
 (0)