Skip to content

Commit

Permalink
archive/scrap SegmentCache, final benchmarks and pending code
Browse files Browse the repository at this point in the history
  • Loading branch information
cehteh committed Jun 12, 2023
1 parent b6a6907 commit 0fd62a4
Show file tree
Hide file tree
Showing 4 changed files with 421 additions and 31 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description = "SegVec data structure for rust. Similar to Vec, but allocates mem

[dev-dependencies]
rand = "0.8.4"
criterion = { version = "0.3.4", features = ["html_reports"] }
criterion = { version = "0.5.1", features = ["html_reports"] }

[dependencies]
smallvec = { version = "1.10.0", features = ["const_generics", "union"], optional = true }
Expand All @@ -24,3 +24,7 @@ thin-segments = ["thin-vec"]
[[bench]]
name = "segvec_benchmark"
harness = false

[[bench]]
name = "segvec_cached"
harness = false
118 changes: 88 additions & 30 deletions benches/segvec_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,81 +3,139 @@ use segvec::*;

pub fn criterion_benchmark(c: &mut Criterion) {
//const N: i32 = 10000;
const N: i32 = 1000000;
c.bench_function("push values on a std Vec", |b| {
const N: i32 = 100000;
//const N: i32 = 1000000;

let mut group = c.benchmark_group("push values");

group.bench_function("std Vec", |b| {
b.iter_with_large_drop(|| {
let mut v: Vec<i32> = Vec::with_capacity(0);
for i in 0..N {
v.push(black_box(i));
}
});
})
.bench_function("push values with default growth factor", |b| {
});

// too slow
// group.bench_function("Linear/factor 1", |b| {
// b.iter_with_large_drop(|| {
// let mut v: SegVec<i32, Linear<1>> = SegVec::with_capacity(0);
// for i in 0..N {
// v.push(black_box(i));
// }
// });
// });

group.bench_function("Proportional/factor 1", |b| {
b.iter_with_large_drop(|| {
let mut v: SegVec<i32> = SegVec::with_capacity(0);
let mut v: SegVec<i32, Proportional<1>> = SegVec::with_capacity(0);
for i in 0..N {
v.push(black_box(i));
}
});
})
.bench_function("push values with large growth factor", |b| {
})
});

group.bench_function("Exponential/factor 1", |b| {
b.iter_with_large_drop(|| {
let mut v: SegVec<i32, Exponential<2500>> = SegVec::with_capacity(0);
let mut v: SegVec<i32, Exponential<1>> = SegVec::with_capacity(0);
for i in 0..N {
v.push(black_box(i));
}
})
})
.bench_function("push values with linear growth, factor 32", |b| {
});
});

group.bench_function("Linear/factor 1024", |b| {
b.iter_with_large_drop(|| {
let mut v: SegVec<i32, Linear<32>> = SegVec::with_capacity(0);
let mut v: SegVec<i32, Linear<1024>> = SegVec::with_capacity(0);
for i in 0..N {
v.push(black_box(i));
}
});
})
.bench_function("push values with proportional growth, factor 32", |b| {
});
group.bench_function("Proportional/factor 1024", |b| {
b.iter_with_large_drop(|| {
let mut v: SegVec<i32, Proportional<32>> = SegVec::with_capacity(0);
let mut v: SegVec<i32, Proportional<1024>> = SegVec::with_capacity(0);
for i in 0..N {
v.push(black_box(i));
}
})
})
.bench_function("push values with exponential growth, factor 32", |b| {
});

group.bench_function("Exponential/factor 1024", |b| {
b.iter_with_large_drop(|| {
let mut v: SegVec<i32, Exponential<32>> = SegVec::with_capacity(0);
let mut v: SegVec<i32, Exponential<1024>> = SegVec::with_capacity(0);
for i in 0..N {
v.push(black_box(i));
}
});
})
.bench_function("push values with linear growth, factor 32, cached", |b| {
});

// too slow
// group.bench_function("Linear/factor 1/cached", |b| {
// b.iter_with_large_drop(|| {
// let mut v: SegVec<i32, Linear<1>> = SegVec::with_capacity(0);
// let mut cache = v.new_cache();
// for i in 0..N {
// v.push_cached(black_box(i), &mut cache);
// }
// });
// });

group.bench_function(
"Proportional/factor 1/cached",
|b| {
b.iter_with_large_drop(|| {
let mut v: SegVec<i32, Proportional<1>> = SegVec::with_capacity(0);
let mut cache = v.new_cache();
for i in 0..N {
v.push_cached(black_box(i), &mut cache);
}
})
},
);

group.bench_function(
"Exponential/factor 1/cached",
|b| {
b.iter_with_large_drop(|| {
let mut v: SegVec<i32, Exponential<1>> = SegVec::with_capacity(0);
let mut cache = v.new_cache();
for i in 0..N {
v.push_cached(black_box(i), &mut cache);
}
});
},
);

group.bench_function("Linear/factor 1024/cached", |b| {
b.iter_with_large_drop(|| {
let mut v: SegVec<i32, Linear<32>> = SegVec::with_capacity(0);
let mut v: SegVec<i32, Linear<1024>> = SegVec::with_capacity(0);
let mut cache = v.new_cache();
for i in 0..N {
v.push_cached(black_box(i), &mut cache);
}
});
})
.bench_function(
"push values with proportional growth, factor 32, cached",
});

group.bench_function(
"Proportional/factor 1024/cached",
|b| {
b.iter_with_large_drop(|| {
let mut v: SegVec<i32, Proportional<32>> = SegVec::with_capacity(0);
let mut v: SegVec<i32, Proportional<1024>> = SegVec::with_capacity(0);
let mut cache = v.new_cache();
for i in 0..N {
v.push_cached(black_box(i), &mut cache);
}
})
},
)
.bench_function(
"push values with exponential growth, factor 32, cached",
);

group.bench_function(
"Exponential/factor 1024/cached",
|b| {
b.iter_with_large_drop(|| {
let mut v: SegVec<i32, Exponential<32>> = SegVec::with_capacity(0);
let mut v: SegVec<i32, Exponential<1024>> = SegVec::with_capacity(0);
let mut cache = v.new_cache();
for i in 0..N {
v.push_cached(black_box(i), &mut cache);
Expand Down
Loading

0 comments on commit 0fd62a4

Please sign in to comment.