Repository navigation
fix(codspeed): changed benches to in-process diff benchmarks to fix codspeed #433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shadowmkj
wants to merge
4
commits into
uutils:main
Choose a base branch
from
shadowmkj:fix/codspeed-benchmarks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
accf44f
fix(benches): changed benches to in-process diff benchmarks
shadowmkj 56995d6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5553fe4
refactor(benches): dedup benchmark logic into helper function
shadowmkj 9d6baad
fix(bench): limit file size for differing files benchmark to prevent OOM
shadowmkj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,9 @@ mod diffutils_cmp { | |
| use diffutilslib::cmp; | ||
| use divan::Bencher; | ||
|
|
||
| use crate::{binary, prepare::*, FILE_SIZE_KILO_BYTES}; | ||
| #[cfg(not(codspeed))] | ||
| use crate::binary; | ||
| use crate::{prepare::*, FILE_SIZE_KILO_BYTES}; | ||
|
|
||
| #[divan::bench(args = FILE_SIZE_KILO_BYTES)] | ||
| fn cmp_compare_files_equal(bencher: Bencher, kb: u64) { | ||
|
|
@@ -56,6 +58,7 @@ mod diffutils_cmp { | |
| } | ||
|
|
||
| // bench original GNU cmp | ||
| #[cfg(not(codspeed))] | ||
| #[divan::bench(args = FILE_SIZE_KILO_BYTES)] | ||
| fn cmd_cmp_gnu_equal(bencher: Bencher, bytes: u64) { | ||
| let (from, to) = get_context().get_test_files_equal(bytes); | ||
|
|
@@ -67,6 +70,7 @@ mod diffutils_cmp { | |
| } | ||
|
|
||
| // bench the compiled release version | ||
| #[cfg(not(codspeed))] | ||
| #[divan::bench(args = FILE_SIZE_KILO_BYTES)] | ||
| fn cmd_cmp_release_equal(bencher: Bencher, bytes: u64) { | ||
| let (from, to) = get_context().get_test_files_equal(bytes); | ||
|
|
@@ -81,28 +85,45 @@ mod diffutils_cmp { | |
|
|
||
| #[cfg(not(feature = "feat_bench_not_diff"))] | ||
| mod diffutils_diff { | ||
| // use std::hint::black_box; | ||
| use std::hint::black_box; | ||
|
|
||
| use crate::{binary, prepare::*, FILE_SIZE_KILO_BYTES}; | ||
| // use diffutilslib::params; | ||
| #[cfg(not(codspeed))] | ||
| use crate::binary; | ||
| use crate::{prepare::*, FILE_SIZE_KILO_BYTES, MB}; | ||
| use diffutilslib::{normal_diff, params}; | ||
| use divan::Bencher; | ||
|
|
||
| // bench the actual compare | ||
| // TODO diff does not have a diff function | ||
| // #[divan::bench(args = [100_000,10_000])] | ||
| // fn diff_compare_files(bencher: Bencher, bytes: u64) { | ||
| // let (from, to) = gen_testfiles(lines, 0, "id"); | ||
| // let cmd = format!("cmp {from} {to}"); | ||
| // let opts = str_to_options(&cmd).into_iter().peekable(); | ||
| // let params = params::parse_params(opts).unwrap(); | ||
| // | ||
| // bencher | ||
| // // .with_inputs(|| prepare::cmp_params_identical_testfiles(lines)) | ||
| // .with_inputs(|| params.clone()) | ||
| // .bench_refs(|params| diff::diff(¶ms).unwrap()); | ||
| // } | ||
| fn bench_diff(bencher: Bencher, from: &str, to: &str) { | ||
| let from_content = std::fs::read(from).expect("Failed to read from file"); | ||
| let to_content = std::fs::read(to).expect("Failed to read to file"); | ||
| let cmd = format!("diff {from} {to}"); | ||
| let opts = str_to_options(&cmd).into_iter().peekable(); | ||
| let (params, _) = params::parse_params(opts).unwrap(); | ||
|
|
||
| bencher | ||
| .with_inputs(|| (&from_content, &to_content, ¶ms)) | ||
| .bench_refs(|(from, to, params)| black_box(normal_diff::diff(from, to, params))); | ||
| } | ||
|
|
||
| // bench the actual diff comparison in-process on identical files | ||
| #[divan::bench(args = FILE_SIZE_KILO_BYTES)] | ||
| fn diff_compare_files_equal(bencher: Bencher, bytes: u64) { | ||
| let (from, to) = get_context().get_test_files_equal(bytes); | ||
| bench_diff(bencher, from, to); | ||
| } | ||
|
|
||
| // bench the actual diff comparison in-process on differing files | ||
| // limiting to 100 KB and 1 MB because the current diff engine allocates O(N*M) | ||
| // memory on differing files, which causes OOM on 10MB/25MB in CodSpeed CI. | ||
| // this must be changed back once https://github.com/uutils/diffutils/issues/401 is resolved | ||
| #[divan::bench(args = [100, MB])] | ||
| fn diff_compare_files_different(bencher: Bencher, bytes: u64) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. almost the same code as |
||
| let (from, to) = get_context().get_test_files_different(bytes); | ||
| bench_diff(bencher, from, to); | ||
| } | ||
|
|
||
| // bench original GNU diff | ||
| #[cfg(not(codspeed))] | ||
| #[divan::bench(args = FILE_SIZE_KILO_BYTES)] | ||
| fn cmd_diff_gnu_equal(bencher: Bencher, bytes: u64) { | ||
| let (from, to) = get_context().get_test_files_equal(bytes); | ||
|
|
@@ -114,6 +135,7 @@ mod diffutils_diff { | |
| } | ||
|
|
||
| // bench the compiled release version | ||
| #[cfg(not(codspeed))] | ||
| #[divan::bench(args = FILE_SIZE_KILO_BYTES)] | ||
| fn cmd_diff_release_equal(bencher: Bencher, bytes: u64) { | ||
| let (from, to) = get_context().get_test_files_equal(bytes); | ||
|
|
@@ -204,7 +226,6 @@ mod prepare { | |
| &self.files_equal[p] | ||
| } | ||
|
|
||
| #[allow(unused)] | ||
| pub fn get_test_files_different(&self, kb: u64) -> &(String, String) { | ||
| let p = FILE_SIZE_KILO_BYTES.iter().position(|f| *f == kb).unwrap(); | ||
| &self.files_different[p] | ||
|
|
@@ -357,15 +378,19 @@ mod prepare { | |
| } | ||
| } | ||
|
|
||
| #[cfg(not(codspeed))] | ||
| mod binary { | ||
| use std::process::Command; | ||
| use std::process::{Command, Stdio}; | ||
|
|
||
| use crate::prepare::str_to_options; | ||
|
|
||
| pub fn bench_binary(program: &str, cmd_args: &str) -> std::process::ExitStatus { | ||
| let args = str_to_options(cmd_args); | ||
| Command::new(program) | ||
| .args(args) | ||
| // Suppress output to prevent terminal I/O overhead from skewing benchmark measurements | ||
| .stdout(Stdio::null()) | ||
| .stderr(Stdio::null()) | ||
| .status() | ||
| .expect("Failed to execute binary") | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please limit these to [100, 1 * MB] for now, the 10/25 MB runs are what kill the codspeed job
we can go back to FILE_SIZE_KILO_BYTES once #401 is fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing! Pushing a commit now