Refactor, bench overwrite
This commit is contained in:
+24
-21
@@ -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");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -15,9 +15,7 @@ const REPEAT: usize = 120;
|
||||
fn build_identity_map(n: usize) -> RangeBoundsMap<usize, Range<usize>, 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");
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user