Skip to content

Commit 77dd93b

Browse files
author
Gunter Schmidt
committed
fix: benchmarks
* fix prg name and parameters * added feature to enable some benches as they should not run during github checks
1 parent b08018f commit 77dd93b

5 files changed

Lines changed: 26 additions & 11 deletions

File tree

src/uu/cmp/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ path = "src/cmp.rs"
2626
# TODO How to sync over all modules?
2727
# instead of limiting to KiB, MiB, etc, one can write kib, mib, Mb or whatever case.
2828
feat_allow_case_insensitive_number_units = []
29+
# default = ["feat_run_binary_bench" ]
30+
# The cmd benchmarks start the binaries and take a lot of runtime on the github checks.
31+
# Only run them locally.
32+
feat_run_binary_bench = []
33+
2934

3035
[dependencies]
3136
# const_format = { workspace = true }

src/uu/cmp/benches/cmp_bench.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use divan::Bencher;
2424
use tempfile::TempDir;
2525
use uu_cmp::parse_params;
2626
use uudiff::benchmark::{
27-
binary,
27+
bench_binary,
2828
prepare_bench::{generate_test_files_bytes, BenchContext},
2929
str_to_args,
3030
};
@@ -74,32 +74,34 @@ fn cmp_compare_files_different(bencher: Bencher, kb: u64) {
7474
}
7575

7676
// bench original GNU cmp
77+
#[cfg(feature = "feat_run_binary_bench")]
7778
#[divan::bench(args = FILE_SIZES_IN_KILO_BYTES)]
7879
fn cmd_cmp_gnu_equal(bencher: Bencher, kb: u64) {
7980
let fp = get_context().get_files_equal_kb(kb).unwrap();
8081
let args_str = format!("{} {}", fp.from, fp.to);
8182
bencher
8283
// .with_inputs(|| prepare::cmp_params_identical_testfiles(lines))
8384
.with_inputs(|| args_str.clone())
84-
.bench_refs(|cmd_args| binary::bench_binary("cmp", cmd_args));
85+
.bench_refs(|cmd_args| bench_binary::bench_binary("cmp", cmd_args));
8586
}
8687

8788
// bench the compiled release version
89+
#[cfg(feature = "feat_run_binary_bench")]
8890
#[divan::bench(args = FILE_SIZES_IN_KILO_BYTES)]
8991
fn cmd_cmp_release_equal(bencher: Bencher, kb: u64) {
9092
// search for src, then shorten path
9193
let dir = std::env::current_dir().unwrap();
9294
let path = dir.to_string_lossy();
9395
let path = path.trim_end_matches("src/uu/cmp");
94-
let prg = path.to_string() + "target/release/diffutils";
96+
let prg = path.to_string() + "target/release/cmp";
9597

9698
let fp = get_context().get_files_equal_kb(kb).unwrap();
97-
let args_str = format!("cmp {} {}", fp.from, fp.to);
99+
let args_str = format!("{} {}", fp.from, fp.to);
98100

99101
bencher
100102
// .with_inputs(|| prepare::cmp_params_identical_testfiles(lines))
101103
.with_inputs(|| args_str.clone())
102-
.bench_refs(|cmd_args| binary::bench_binary(&prg, cmd_args));
104+
.bench_refs(|cmd_args| bench_binary::bench_binary(&prg, cmd_args));
103105
}
104106

105107
// Since each bench function is separate in Divan it is more difficult to dynamically create test data.

src/uu/diff/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ path = "src/main.rs"
2222
[lib]
2323
path = "src/diff.rs"
2424

25+
[features]
26+
# default = ["feat_run_binary_bench" ]
27+
# The cmd benchmarks start the binaries and take a lot of runtime on the github checks.
28+
# Only run them locally.
29+
feat_run_binary_bench = []
30+
2531
[dependencies]
2632
# const_format = { workspace = true }
2733
diff_crate = { workspace = true }

src/uu/diff/benches/diff_bench.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use divan::Bencher;
2222
use std::{path::Path, sync::OnceLock};
2323
use tempfile::TempDir;
2424
use uudiff::benchmark::{
25-
binary,
25+
bench_binary,
2626
prepare_bench::{generate_test_files_bytes, BenchContext},
2727
str_to_args,
2828
};
@@ -52,32 +52,34 @@ fn diff_compare_files_equal(bencher: Bencher, kb: u64) {
5252
}
5353

5454
// bench original GNU diff
55+
#[cfg(feature = "feat_run_binary_bench")]
5556
#[divan::bench(args = FILE_SIZES_IN_KILO_BYTES)]
5657
fn cmd_diff_gnu_equal(bencher: Bencher, kb: u64) {
5758
let fp = get_context().get_files_equal_kb(kb).unwrap();
5859
let args_str = format!("{} {}", fp.from, fp.to);
5960
bencher
6061
// .with_inputs(|| prepare::cmp_params_identical_testfiles(lines))
6162
.with_inputs(|| args_str.clone())
62-
.bench_refs(|cmd_args| binary::bench_binary("diff", cmd_args));
63+
.bench_refs(|cmd_args| bench_binary::bench_binary("diff", cmd_args));
6364
}
6465

6566
// bench the compiled release version
67+
#[cfg(feature = "feat_run_binary_bench")]
6668
#[divan::bench(args = FILE_SIZES_IN_KILO_BYTES)]
6769
fn cmd_diff_release_equal(bencher: Bencher, kb: u64) {
6870
// search for src, then shorten path
6971
let dir = std::env::current_dir().unwrap();
7072
let path = dir.to_string_lossy();
7173
let path = path.trim_end_matches("src/uu/diff");
72-
let prg = path.to_string() + "target/release/diffutils";
74+
let prg = path.to_string() + "target/release/diff";
7375

7476
let fp = get_context().get_files_equal_kb(kb).unwrap();
75-
let args_str = format!("diff {} {}", fp.from, fp.to);
77+
let args_str = format!("{} {}", fp.from, fp.to);
7678

7779
bencher
7880
// .with_inputs(|| prepare::cmp_params_identical_testfiles(lines))
7981
.with_inputs(|| args_str.clone())
80-
.bench_refs(|cmd_args| binary::bench_binary(&prg, cmd_args));
82+
.bench_refs(|cmd_args| bench_binary::bench_binary(&prg, cmd_args));
8183
}
8284

8385
// Since each bench function is separate in Divan it is more difficult to dynamically create test data.

src/uudiff/src/lib/features/benchmark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ pub mod prepare_bench {
215215
}
216216

217217
/// Benchmark tools which are designed to call the compiled executable.
218-
pub mod binary {
218+
pub mod bench_binary {
219219
use std::process::Command;
220220

221221
use crate::benchmark::str_to_args;

0 commit comments

Comments
 (0)