diff options
author | Aria <me@aria.rip> | 2023-11-07 22:25:18 +0000 |
---|---|---|
committer | Aria <me@aria.rip> | 2023-11-07 22:25:18 +0000 |
commit | c6be430616e97a5bca0ee56f71908589b174a8ff (patch) | |
tree | 382857e2b9ac41881d58dad5d33670101f177752 /src/crates/primrose/benches | |
parent | 71236e6332507ef18d14876d200ac83bf895496a (diff) |
refactor(all): shorter directory names
Diffstat (limited to 'src/crates/primrose/benches')
-rw-r--r-- | src/crates/primrose/benches/criterion_benchmark.rs | 235 |
1 files changed, 235 insertions, 0 deletions
diff --git a/src/crates/primrose/benches/criterion_benchmark.rs b/src/crates/primrose/benches/criterion_benchmark.rs new file mode 100644 index 0000000..6bdc214 --- /dev/null +++ b/src/crates/primrose/benches/criterion_benchmark.rs @@ -0,0 +1,235 @@ +use criterion::{criterion_group, criterion_main, Criterion}; + +use primrose_library::traits::Container; +use primrose_library::LazyUniqueVec; +use rand::rngs::StdRng; +use rand::seq::SliceRandom; + +use rand::SeedableRng; +use std::collections::{BTreeSet, HashSet}; +use std::mem::size_of; + +use std::vec::Vec; + +// one search at the +fn gen_dataset_1() -> Vec<u32> { + // avoid duplication + let size = 1024 * 1024; // 1 MB + let amount = size / size_of::<u32>(); + let mut data: Vec<u32> = (1..amount as u32).collect(); //ensure no duplication + let mut rng = StdRng::seed_from_u64(222); + data.shuffle(&mut rng); + data +} + +fn gen_dataset_128() -> Vec<u32> { + // avoid duplication + let size = 128 * 1024 * 1024; // 128 MB + let amount = size / size_of::<u32>(); + let mut data: Vec<u32> = (1..amount as u32).collect(); //ensure no duplication + let mut rng = StdRng::seed_from_u64(222); + data.shuffle(&mut rng); + data +} + +fn gen_dataset_256() -> Vec<u32> { + // avoid duplication + let size = 256 * 1024 * 1024; // 256 MB + let amount = size / size_of::<u32>(); + let mut data: Vec<u32> = (1..amount as u32).collect(); //ensure no duplication + let mut rng = StdRng::seed_from_u64(222); + data.shuffle(&mut rng); + data +} + +fn gen_dataset_512() -> Vec<u32> { + // avoid duplication + let size = 512 * 1024 * 1024; // 512 MB + let amount = size / size_of::<u32>(); + let mut data: Vec<u32> = (1..amount as u32).collect(); //ensure no duplication + let mut rng = StdRng::seed_from_u64(222); + data.shuffle(&mut rng); + data +} + +fn btreeset_insertion_1m(c: &mut Criterion) { + let s: &mut dyn Container<u32> = &mut BTreeSet::new(); + let data = gen_dataset_1(); + c.bench_function("btreeset insertion 1MB", |b| { + b.iter(|| { + for val in data.iter() { + s.insert(*val); + } + s.contains(&1024); + }) + }); +} + +fn btreeset_insertion_128m(c: &mut Criterion) { + let s: &mut dyn Container<u32> = &mut BTreeSet::new(); + let data = gen_dataset_128(); + c.bench_function("btreeset insertion 128MB", |b| { + b.iter(|| { + for val in data.iter() { + s.insert(*val); + } + s.contains(&1024); + }) + }); +} + +fn btreeset_insertion_256m(c: &mut Criterion) { + let s: &mut dyn Container<u32> = &mut BTreeSet::new(); + let data = gen_dataset_256(); + c.bench_function("btreeset insertion 256MB", |b| { + b.iter(|| { + for val in data.iter() { + s.insert(*val); + } + s.contains(&1024); + }) + }); +} + +fn btreeset_insertion_512m(c: &mut Criterion) { + let s: &mut dyn Container<u32> = &mut BTreeSet::new(); + let data = gen_dataset_512(); + c.bench_function("btreeset insertion 512MB", |b| { + b.iter(|| { + for val in data.iter() { + s.insert(*val); + } + s.contains(&1024); + }) + }); +} + +fn hashset_insertion_1m(c: &mut Criterion) { + let s: &mut dyn Container<u32> = &mut HashSet::new(); + let data = gen_dataset_1(); + c.bench_function("hashset insertion 1MB", |b| { + b.iter(|| { + for val in data.iter() { + s.insert(*val); + } + s.contains(&1024); + }) + }); +} + +fn hashset_insertion_128m(c: &mut Criterion) { + let s: &mut dyn Container<u32> = &mut HashSet::new(); + let data = gen_dataset_128(); + c.bench_function("hashset insertion 128MB", |b| { + b.iter(|| { + for val in data.iter() { + s.insert(*val); + } + s.contains(&1024); + }) + }); +} + +fn hashset_insertion_256m(c: &mut Criterion) { + let s: &mut dyn Container<u32> = &mut HashSet::new(); + let data = gen_dataset_256(); + c.bench_function("hashset insertion 256MB", |b| { + b.iter(|| { + for val in data.iter() { + s.insert(*val); + } + s.contains(&1024); + }) + }); +} + +fn hashset_insertion_512m(c: &mut Criterion) { + let s: &mut dyn Container<u32> = &mut HashSet::new(); + let data = gen_dataset_512(); + c.bench_function("hashset insertion 512MB", |b| { + b.iter(|| { + for val in data.iter() { + s.insert(*val); + } + s.contains(&1024); + }) + }); +} + +fn lazy_uniuqe_vec_insertion_1m(c: &mut Criterion) { + let s: &mut dyn Container<u32> = &mut LazyUniqueVec::new(); + let data = gen_dataset_1(); + c.bench_function("lazy unique vector insertion 1MB", |b| { + b.iter(|| { + for val in data.iter() { + s.insert(*val); + } + s.contains(&1024); + }) + }); +} + +fn lazy_uniuqe_vec_insertion_128m(c: &mut Criterion) { + let s: &mut dyn Container<u32> = &mut LazyUniqueVec::new(); + let data = gen_dataset_128(); + c.bench_function("lazy unique vector insertion 128MB", |b| { + b.iter(|| { + for val in data.iter() { + s.insert(*val); + } + s.contains(&1024); + }) + }); +} + +fn lazy_uniuqe_vec_insertion_256m(c: &mut Criterion) { + let s: &mut dyn Container<u32> = &mut LazyUniqueVec::new(); + let data = gen_dataset_256(); + c.bench_function("lazy unique vector insertion 256MB", |b| { + b.iter(|| { + for val in data.iter() { + s.insert(*val); + } + s.contains(&1024); + }) + }); +} + +fn lazy_uniuqe_vec_insertion_512m(c: &mut Criterion) { + let s: &mut dyn Container<u32> = &mut LazyUniqueVec::new(); + let data = gen_dataset_512(); + c.bench_function("lazy unique vector insertion 512MB", |b| { + b.iter(|| { + for val in data.iter() { + s.insert(*val); + } + s.contains(&1024); + }) + }); +} + +criterion_group! { + name = insertion_1m; + config = Criterion::default().sample_size(10); + targets = btreeset_insertion_1m, hashset_insertion_1m, lazy_uniuqe_vec_insertion_1m +} + +criterion_group! { + name = insertion_128m; + config = Criterion::default().sample_size(10); + targets = btreeset_insertion_128m, hashset_insertion_128m, lazy_uniuqe_vec_insertion_128m +} + +criterion_group! { + name = insertion_256m; + config = Criterion::default().sample_size(10); + targets = btreeset_insertion_256m, hashset_insertion_256m, lazy_uniuqe_vec_insertion_256m +} + +criterion_group! { + name = insertion_512m; + config = Criterion::default().sample_size(10); + targets = btreeset_insertion_512m, hashset_insertion_512m, lazy_uniuqe_vec_insertion_512m +} + +criterion_main!(insertion_1m, insertion_128m, insertion_256m, insertion_512m); |