speed it up by parallelizing the 20 iterations
This commit is contained in:
parent
78a1b3bc5a
commit
b341d9d1cb
1 changed files with 9 additions and 6 deletions
|
@ -101,17 +101,17 @@ fn main() -> io::Result<()> {
|
||||||
if rand_heights_clone.get(&n).is_some() {
|
if rand_heights_clone.get(&n).is_some() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
println!("{}: starting n: {n}", current_thread_index().unwrap());
|
println!("{thread}: starting n: {n}", thread = current_thread_index().unwrap());
|
||||||
|
|
||||||
asc_results_clone.insert(n, vec![]);
|
asc_results_clone.insert(n, vec![]);
|
||||||
asc_heights_clone.insert(n, vec![]);
|
asc_heights_clone.insert(n, vec![]);
|
||||||
rand_results_clone.insert(n, vec![]);
|
rand_results_clone.insert(n, vec![]);
|
||||||
rand_heights_clone.insert(n, vec![]);
|
rand_heights_clone.insert(n, vec![]);
|
||||||
|
|
||||||
|
(1..=m).into_par_iter().for_each(|k| {
|
||||||
|
println!("{thread}: starting iteration {k}/{m} for n: {n}", thread = current_thread_index().unwrap());
|
||||||
let mut asc = BinarySearchTree::new(n as usize);
|
let mut asc = BinarySearchTree::new(n as usize);
|
||||||
let mut rand = BinarySearchTree::new(n as usize);
|
|
||||||
|
|
||||||
for _ in 0..m {
|
|
||||||
for i in gen_asc(n) {
|
for i in gen_asc(n) {
|
||||||
asc.insert(i);
|
asc.insert(i);
|
||||||
asc_heights_clone.get_mut(&n).unwrap().push(asc.height());
|
asc_heights_clone.get_mut(&n).unwrap().push(asc.height());
|
||||||
|
@ -123,6 +123,8 @@ fn main() -> io::Result<()> {
|
||||||
|
|
||||||
asc_results_clone.get_mut(&n).unwrap().push(asc.stats.clone());
|
asc_results_clone.get_mut(&n).unwrap().push(asc.stats.clone());
|
||||||
|
|
||||||
|
let mut rand = BinarySearchTree::new(n as usize);
|
||||||
|
|
||||||
for i in gen_rand(n) {
|
for i in gen_rand(n) {
|
||||||
rand.insert(i);
|
rand.insert(i);
|
||||||
rand_heights_clone.get_mut(&n).unwrap().push(rand.height());
|
rand_heights_clone.get_mut(&n).unwrap().push(rand.height());
|
||||||
|
@ -133,8 +135,9 @@ fn main() -> io::Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
rand_results_clone.get_mut(&n).unwrap().push(rand.stats.clone());
|
rand_results_clone.get_mut(&n).unwrap().push(rand.stats.clone());
|
||||||
}
|
println!("{thread}: finished iteration {k}/{m} for n: {n}", thread = current_thread_index().unwrap());
|
||||||
println!("{}: finished n: {n}", current_thread_index().unwrap());
|
});
|
||||||
|
println!("{thread}: finished n: {n}", thread = current_thread_index().unwrap());
|
||||||
});
|
});
|
||||||
|
|
||||||
let asc_comp_averages = comp_avg(&asc_results);
|
let asc_comp_averages = comp_avg(&asc_results);
|
||||||
|
|
Loading…
Reference in a new issue