Skip to content

Commit 81c6dd2

Browse files
committed
feat: greatly improve performance and realism of baseline-atomic test. (#30)
We now set a fixed amount of 'big' steps along with one of those chunks being a range where the step-size is one commit at a time, which might be the way changes are obtained in the future.
1 parent 4dd4a4c commit 81c6dd2

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

tests/baseline_atomic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ mod shared;
55
#[cfg_attr(debug_assertions, ignore)]
66
#[test]
77
fn one_per_commit() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
8-
shared::baseline(Step::OnePerCommit)
8+
shared::baseline(Step::Realistic { partitions: 40 })
99
}

tests/shared/mod.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ use crates_index_diff::Change::*;
33

44
#[allow(dead_code)]
55
pub enum Step {
6-
Partitioned { size: usize },
7-
OnePerCommit,
6+
Partitioned {
7+
size: usize,
8+
},
9+
Realistic {
10+
/// Like `Partitioned::size, and used to have big steps until the last partition which is then single-steped entirely.
11+
partitions: usize,
12+
},
813
}
914

1015
pub fn baseline(mode: Step) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
@@ -37,16 +42,21 @@ pub fn baseline(mode: Step) -> Result<(), Box<dyn std::error::Error + Send + Syn
3742
.collect::<Result<Vec<_>, _>>()?;
3843

3944
// This could be more complex, like jumping to landmarks like 'Delete crate(s)' and so forth.
40-
let partitions = match mode {
41-
Step::Partitioned { size } => size,
42-
Step::OnePerCommit => commits.len(),
45+
let (partitions, last_partition_is_single_step) = match mode {
46+
Step::Partitioned { size } => (size, false),
47+
Step::Realistic { partitions } => (partitions, true),
4348
};
4449
let chunk_size = (commits.len() / partitions).max(1);
45-
let mut steps = (0..commits.len()).step_by(chunk_size).collect::<Vec<_>>();
50+
let mut steps = if last_partition_is_single_step && chunk_size > 1 {
51+
let mut steps: Vec<_> = (0..chunk_size).collect();
52+
steps.extend((chunk_size..commits.len()).step_by(chunk_size));
53+
steps
54+
} else {
55+
(0..commits.len()).step_by(chunk_size).collect::<Vec<_>>()
56+
};
4657
if *steps.last().expect("at least 1") != commits.len() - 1 {
4758
steps.push(commits.len() - 1);
4859
}
49-
5060
let mut versions = HashMap::default();
5161
let mut previous = None;
5262
let num_steps = steps.len();

0 commit comments

Comments
 (0)