feat: attempt to benchmark another implementation from crates.io
This commit is contained in:
parent
1e45ef9314
commit
131d9f3cfe
4 changed files with 300 additions and 8 deletions
|
|
@ -4,6 +4,10 @@ use peoplesgrocers_lseq::{SortKey, LSEQ};
|
|||
use peoplesgrocers_lseq_research::algorithms::lseq_base64::{LSEQBase64, SortKeyBase64};
|
||||
use rand::{Rng, rngs::StdRng, SeedableRng};
|
||||
use std::collections::VecDeque;
|
||||
// Add lseq crate from crates.io (uses arbitrary precision arithmetic)
|
||||
// This crate does not compile on arm
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
use lseq::{LSEQ as LSEQArbitraryPrecision, Ident};
|
||||
|
||||
fn benchmark_sequential_insertions(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("sequential_insertions");
|
||||
|
|
@ -68,6 +72,28 @@ fn benchmark_sequential_insertions(c: &mut Criterion) {
|
|||
});
|
||||
},
|
||||
);
|
||||
|
||||
// Benchmark lseq crate from crates.io (arbitrary precision arithmetic)
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
group.bench_with_input(
|
||||
BenchmarkId::new("arbitrary_precision", size),
|
||||
size,
|
||||
|b, &size| {
|
||||
b.iter(|| {
|
||||
let mut lseq = LSEQArbitraryPrecision::new();
|
||||
let mut keys = Vec::new();
|
||||
|
||||
for _ in 0..size {
|
||||
let before = keys.last();
|
||||
let after = None;
|
||||
let key = lseq.allocate(before, after);
|
||||
keys.push(key);
|
||||
}
|
||||
|
||||
black_box(keys);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
group.finish();
|
||||
|
|
@ -163,6 +189,36 @@ fn benchmark_random_insertions(c: &mut Criterion) {
|
|||
});
|
||||
},
|
||||
);
|
||||
|
||||
// Benchmark lseq crate from crates.io (arbitrary precision arithmetic)
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
group.bench_with_input(
|
||||
BenchmarkId::new("arbitrary_precision", size),
|
||||
size,
|
||||
|b, &size| {
|
||||
b.iter(|| {
|
||||
let mut lseq = LSEQArbitraryPrecision::new();
|
||||
let mut keys = Vec::new();
|
||||
let mut rng = StdRng::seed_from_u64(123);
|
||||
|
||||
for _ in 0..size {
|
||||
if keys.is_empty() {
|
||||
let key = lseq.allocate(None, None);
|
||||
keys.push(key);
|
||||
} else {
|
||||
let idx = rng.gen_range(0..keys.len());
|
||||
let before = if idx == 0 { None } else { Some(&keys[idx - 1]) };
|
||||
let after = if idx == keys.len() { None } else { Some(&keys[idx]) };
|
||||
|
||||
let key = lseq.allocate(before, after);
|
||||
keys.insert(idx, key);
|
||||
}
|
||||
}
|
||||
|
||||
black_box(keys);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
group.finish();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue