Fixate random seeds for benchmark

This commit is contained in:
Dirkjan Ochtman 2021-05-20 14:18:26 +02:00
parent b1bd3525a1
commit c8a9529355
1 changed files with 5 additions and 4 deletions

View File

@ -1,5 +1,5 @@
use bencher::{benchmark_group, benchmark_main, Bencher}; use bencher::{benchmark_group, benchmark_main, Bencher};
use rand::rngs::{StdRng, ThreadRng}; use rand::rngs::StdRng;
use rand::{Rng, SeedableRng}; use rand::{Rng, SeedableRng};
use instant_distance::Builder; use instant_distance::Builder;
@ -8,16 +8,17 @@ benchmark_main!(benches);
benchmark_group!(benches, build_heuristic); benchmark_group!(benches, build_heuristic);
fn build_heuristic(bench: &mut Bencher) { fn build_heuristic(bench: &mut Bencher) {
let seed = ThreadRng::default().gen::<u64>(); let mut rng = StdRng::seed_from_u64(SEED);
let mut rng = StdRng::seed_from_u64(seed);
let points = (0..1024) let points = (0..1024)
.into_iter() .into_iter()
.map(|_| Point(rng.gen(), rng.gen())) .map(|_| Point(rng.gen(), rng.gen()))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
bench.iter(|| Builder::default().seed(seed).build_hnsw(points.clone())) bench.iter(|| Builder::default().seed(SEED).build_hnsw(points.clone()))
} }
const SEED: u64 = 123456789;
/* /*
fn randomized(builder: Builder) -> (u64, usize) { fn randomized(builder: Builder) -> (u64, usize) {
let query = Point(rng.gen(), rng.gen()); let query = Point(rng.gen(), rng.gen());