mirror of
https://github.com/qdrant/qdrant.git
synced 2026-08-04 00:51:06 -05:00
* Benches: use SmallRng instead of ChaCha12-based generators All benchmarks used StdRng or rand::rng() (ThreadRng), both backed by the ChaCha12 block cipher in rand 0.10. Benchmarks do not need crypto-strength randomness, and several draw random values inside the timed closure, so cipher work was included in the measurement itself. Switch every bench target to SmallRng (Xoshiro256++), and key the HNSW graph cache and sparse index cache by RNG algorithm so stale caches built from the old generator are not reused against newly generated vectors. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Benches: replace free-function rand::random with local SmallRng Addresses review: rand::random draws from the thread RNG (ChaCha12), including inside the timed loop of the pq score benchmark. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
72 lines
2.3 KiB
Rust
72 lines
2.3 KiB
Rust
#[cfg(not(target_os = "windows"))]
|
|
mod prof;
|
|
|
|
use std::collections::{BTreeMap, HashMap};
|
|
|
|
use criterion::{Criterion, criterion_group, criterion_main};
|
|
use rand::SeedableRng;
|
|
use rand::rngs::SmallRng;
|
|
use segment::data_types::tiny_map::TinyMap;
|
|
use segment::fixtures::index_fixtures::random_vector;
|
|
|
|
const DIM: usize = 100;
|
|
|
|
fn small_map_obj(c: &mut Criterion) {
|
|
let mut group = c.benchmark_group("small-map-obj-group");
|
|
|
|
let mut rng = SmallRng::seed_from_u64(42);
|
|
let default_key = "vector".to_string();
|
|
let default_key_2 = "vector1".to_string();
|
|
let default_key_3 = "vector2".to_string();
|
|
let random_vector = random_vector(&mut rng, DIM);
|
|
|
|
group.bench_function("hash-map", |b| {
|
|
b.iter(|| {
|
|
let mut map = HashMap::new();
|
|
map.insert(default_key.clone(), random_vector.clone());
|
|
map.insert(default_key_2.clone(), random_vector.clone());
|
|
map.insert(default_key_3.clone(), random_vector.clone());
|
|
let _ = map.get(&default_key_3);
|
|
});
|
|
});
|
|
|
|
group.bench_function("btree-map", |b| {
|
|
b.iter(|| {
|
|
let mut map = BTreeMap::new();
|
|
map.insert(default_key.clone(), random_vector.clone());
|
|
map.insert(default_key_2.clone(), random_vector.clone());
|
|
map.insert(default_key_3.clone(), random_vector.clone());
|
|
let _ = map.get(&default_key_3);
|
|
});
|
|
});
|
|
|
|
#[allow(clippy::vec_init_then_push)]
|
|
group.bench_function("vec-map", |b| {
|
|
b.iter(|| {
|
|
let mut map = Vec::with_capacity(3);
|
|
map.push((default_key.clone(), random_vector.clone()));
|
|
map.push((default_key_2.clone(), random_vector.clone()));
|
|
map.push((default_key_3.clone(), random_vector.clone()));
|
|
let _ = map.iter().find(|(k, _)| k == &default_key_3);
|
|
});
|
|
});
|
|
|
|
group.bench_function("tiny-map", |b| {
|
|
b.iter(|| {
|
|
let mut map = TinyMap::new();
|
|
map.insert(default_key.clone(), random_vector.clone());
|
|
map.insert(default_key_2.clone(), random_vector.clone());
|
|
map.insert(default_key_3.clone(), random_vector.clone());
|
|
let _ = map.get(&default_key_3);
|
|
});
|
|
});
|
|
}
|
|
|
|
criterion_group! {
|
|
name = benches;
|
|
config = Criterion::default();
|
|
targets = small_map_obj
|
|
}
|
|
|
|
criterion_main!(benches);
|