From 1ea738bd79d8cedf48900ef3dc40ac5e736b1388 Mon Sep 17 00:00:00 2001 From: Mikolaj Figurski Date: Fri, 13 Jan 2023 14:01:51 -0500 Subject: [PATCH] Refactor, bench overwrite --- benches/insert.rs | 45 +++++++++++++++++++++++-------------------- benches/operations.rs | 13 ++++--------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/benches/insert.rs b/benches/insert.rs index 71e06e1..0d0c89e 100644 --- a/benches/insert.rs +++ b/benches/insert.rs @@ -15,9 +15,7 @@ fn bench_insert_platonic(b: &mut Bencher) { let mut map = RangeBoundsMap::new(); for i in 0..REPEAT { let r = i..=i; - if let Err(OverlapError) = map.insert_platonic(r, i) { - panic!("Failed to insert"); - } + map.insert_platonic(r, i).expect("insert failed"); } }); } @@ -29,12 +27,10 @@ fn bench_insert_coalesce_touching(b: &mut Bencher) { for i in 0..REPEAT / 2 { let r1 = (10 * i)..(10 * i + 1); let r2 = (10 * i + 1)..(10 * i + 2); - if let Err(e) = map.insert_coalesce_touching(r1, true) { - panic!("Failed to insert: {:?}", e) - } - if let Err(e) = map.insert_coalesce_touching(r2, true) { - panic!("Failed to insert: {:?}", e) - } + map.insert_coalesce_touching(r1, true) + .expect("Failed to insert"); + map.insert_coalesce_touching(r2, true) + .expect("Failed to insert"); } }) } @@ -46,12 +42,10 @@ fn bench_insert_coalesce_overlapping(b: &mut Bencher) { for i in 0..REPEAT / 2 { let r1 = (10 * i)..(10 * i + 1); let r2 = (10 * i)..(10 * i + 2); - if let Err(e) = map.insert_coalesce_overlapping(r1, true) { - panic!("Failed to insert: {:?}", e) - } - if let Err(e) = map.insert_coalesce_overlapping(r2, true) { - panic!("Failed to insert: {:?}", e) - } + map.insert_coalesce_overlapping(r1, true) + .expect("Failed to insert"); + map.insert_coalesce_overlapping(r2, true) + .expect("Failed to insert"); } }) } @@ -63,12 +57,21 @@ fn bench_insert_coalesce_touching_or_overlapping(b: &mut Bencher) { for i in 0..REPEAT / 2 { let r1 = (10 * i + 1)..(10 * i + 2); let r2 = (10 * i)..(10 * i + 4); - if let Err(e) = map.insert_coalesce_touching_or_overlapping(r1, 1) { - panic!("Failed to insert: {:?}", e) - } - if let Err(e) = map.insert_coalesce_touching_or_overlapping(r2, 2) { - panic!("Failed to insert: {:?}", e) - } + map.insert_coalesce_touching_or_overlapping(r1, 1) + .expect("Failed to insert"); + map.insert_coalesce_touching_or_overlapping(r2, 2) + .expect("Failed to insert"); } }) } + +#[bench] +fn bench_overwrite(b: &mut Bencher) { + b.iter(|| { + let mut map = RangeBoundsMap::new(); + for i in 0..REPEAT { + let r = i..i + 2; + map.overwrite(r, i).expect("insert failed"); + } + }); +} diff --git a/benches/operations.rs b/benches/operations.rs index 3cc42c2..a6d36ff 100644 --- a/benches/operations.rs +++ b/benches/operations.rs @@ -15,9 +15,7 @@ const REPEAT: usize = 120; fn build_identity_map(n: usize) -> RangeBoundsMap, usize> { let mut map = RangeBoundsMap::new(); for i in 0..n { - if let Err(OverlapError) = map.insert_platonic(i..i + 1, i) { - panic!("Failed to insert") - } + map.insert_platonic(i..i + 1, i).expect("insert failed"); } map } @@ -48,9 +46,7 @@ fn bench_cut(b: &mut Bencher) { let map = build_identity_map(REPEAT); b.iter(|| { let mut map = map.clone(); - if let Err(e) = map.cut(&(0..REPEAT)) { - panic!("Failed to cut: {:?}", e) - } + for _ in map.cut(&(0..REPEAT)).expect("Failed to cut") {} }) } @@ -65,9 +61,8 @@ fn bench_split_off(b: &mut Bencher) { let map = build_identity_map(REPEAT); b.iter(|| { let mut map = map.clone(); - if let Err(e) = map.split_off(Bound::Included(REPEAT / 2)) { - panic!("Failed to split: {:?}", e) - } + map.split_off(Bound::Included(REPEAT / 2)) + .expect("Failed to split"); }) }