Skip to content

Commit

Permalink
fix benches
Browse files Browse the repository at this point in the history
  • Loading branch information
azizkayumov committed Jan 2, 2024
1 parent 23b3ebf commit f2f5ec1
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,40 @@ use criterion::{criterion_group, criterion_main, Criterion};
use rand::{rngs::StdRng, Rng, SeedableRng};
use rindex::Index;

fn benchmark(criterion: &mut Criterion) {
let k = 10;
let n = 10000;
let seed = 0;
const K: usize = 10;
const SEED: u64 = 0;
const N: usize = 10000;

fn benchmark(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("rknn");
group.sample_size(10);

group.bench_function("SSTree", |b| b.iter(|| bench_sstree(k, n, seed)));
group.bench_function("Linear", |b| b.iter(|| bench_linear(k, n, seed)));
group.bench_function("SSTree", |b| b.iter(|| bench_sstree()));
group.bench_function("Linear", |b| b.iter(|| bench_linear()));
}

criterion_group!(benches, benchmark);
criterion_main!(benches);

fn bench_sstree(k: usize, n: usize, seed: u64) {
let mut tree = rindex::SSTree::new(k);
let mut rng = StdRng::seed_from_u64(seed);
for _ in 0..n {
let point = [rng.gen(), rng.gen()];
tree.rknn(point);
tree.insert(point);
fn bench_sstree() {
let mut tree = rindex::SSTree::new(K);
let pts = dataset();
for p in pts {
tree.rknn(p);
tree.insert(p);
}
}

fn bench_linear(k: usize, n: usize, seed: u64) {
let mut linear = rindex::LinearIndex::new(k);
let mut rng = StdRng::seed_from_u64(seed);
for _ in 0..n {
let point = [rng.gen(), rng.gen()];
fn bench_linear() {
let mut linear = rindex::LinearIndex::new(K);
let dataset = dataset();
for point in dataset {
linear.rknn(point);
linear.insert(point);
}
}

fn dataset() -> Vec<[f64; 2]> {
let mut rng = StdRng::seed_from_u64(SEED);
(0..N).map(|_| [rng.gen(), rng.gen()]).collect()
}

0 comments on commit f2f5ec1

Please sign in to comment.