break apart writes to points, doesn't help
This commit is contained in:
parent
46f6fa3e28
commit
36c1a64e54
1 changed files with 61 additions and 23 deletions
|
@ -77,43 +77,57 @@ impl Spindex2d {
|
||||||
index
|
index
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This method assumes that the points have the same cardinality and order as the points used
|
||||||
|
/// when constructing this index. May panic if the updated points argument is longer than the
|
||||||
|
/// original points.
|
||||||
|
pub fn update(&self, points: &[Point2d]) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
fn sort(&self) {
|
fn sort(&self) {
|
||||||
let xs = self.xs.clone();
|
let xs = self.xs.clone();
|
||||||
let ys = self.ys.clone();
|
|
||||||
let xpoints = self.points.clone();
|
|
||||||
let ypoints = self.points.clone();
|
|
||||||
|
|
||||||
let xhandle = thread::spawn(move || {
|
let xhandle = thread::spawn(move || {
|
||||||
{
|
|
||||||
let mut xs = xs.write().unwrap();
|
let mut xs = xs.write().unwrap();
|
||||||
xs.sort_unstable_by(|a, b| {
|
xs.sort_unstable_by(|a, b| {
|
||||||
let a = a.read().unwrap();
|
let a = a.read().unwrap();
|
||||||
let b = b.read().unwrap();
|
let b = b.read().unwrap();
|
||||||
a.cmp(&b)
|
a.cmp(&b)
|
||||||
});
|
});
|
||||||
}
|
|
||||||
let xs = xs.read().unwrap();
|
|
||||||
for (i, x) in xs.iter().enumerate() {
|
|
||||||
let x = x.read().unwrap();
|
|
||||||
let p = x.point;
|
|
||||||
xpoints[p].write().unwrap().x = i;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let ys = self.ys.clone();
|
||||||
let yhandle = thread::spawn(move || {
|
let yhandle = thread::spawn(move || {
|
||||||
{
|
|
||||||
let mut ys = ys.write().unwrap();
|
let mut ys = ys.write().unwrap();
|
||||||
ys.sort_unstable_by(|a, b| {
|
ys.sort_unstable_by(|a, b| {
|
||||||
let a = a.read().unwrap();
|
let a = a.read().unwrap();
|
||||||
let b = b.read().unwrap();
|
let b = b.read().unwrap();
|
||||||
a.cmp(&b)
|
a.cmp(&b)
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
xhandle.join().unwrap();
|
||||||
|
yhandle.join().unwrap();
|
||||||
|
|
||||||
|
let xs = self.xs.clone();
|
||||||
|
let points = self.points.clone();
|
||||||
|
let xhandle = thread::spawn(move || {
|
||||||
|
let xs = xs.read().unwrap();
|
||||||
|
for (i, x) in xs.iter().enumerate() {
|
||||||
|
let x = x.read().unwrap();
|
||||||
|
let p = x.point;
|
||||||
|
points[p].write().unwrap().x = i;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let ys = self.ys.clone();
|
||||||
|
let points = self.points.clone();
|
||||||
|
let yhandle = thread::spawn(move || {
|
||||||
let ys = ys.read().unwrap();
|
let ys = ys.read().unwrap();
|
||||||
|
|
||||||
for (i, y) in ys.iter().enumerate() {
|
for (i, y) in ys.iter().enumerate() {
|
||||||
let y = y.read().unwrap();
|
let y = y.read().unwrap();
|
||||||
let p = y.point;
|
let p = y.point;
|
||||||
ypoints[p].write().unwrap().y = i;
|
points[p].write().unwrap().y = i;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -139,7 +153,7 @@ const SEED_1: &[u8; 32] = b"Gv0aHMtHkBGsUXNspGU9fLRuCWkZWHZx";
|
||||||
const DEFAULT_NUM_POINTS: usize = 1_000_000;
|
const DEFAULT_NUM_POINTS: usize = 1_000_000;
|
||||||
|
|
||||||
fn new_index(c: &mut Criterion) {
|
fn new_index(c: &mut Criterion) {
|
||||||
c.bench_function("bulk load baseline", move |b| {
|
c.bench_function("new index", move |b| {
|
||||||
let points: Vec<_> = create_random_points(DEFAULT_NUM_POINTS, SEED_1)
|
let points: Vec<_> = create_random_points(DEFAULT_NUM_POINTS, SEED_1)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|[x, y]| Point2d { x, y })
|
.map(|[x, y]| Point2d { x, y })
|
||||||
|
@ -151,6 +165,30 @@ fn new_index(c: &mut Criterion) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn update_positions(c: &mut Criterion) {
|
||||||
|
c.bench_function("update positions", move |b| {
|
||||||
|
let points: Vec<_> = create_random_points(DEFAULT_NUM_POINTS, SEED_1)
|
||||||
|
.into_iter()
|
||||||
|
.map(|[x, y]| Point2d { x, y })
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let mut rng = Hc128Rng::from_seed(*SEED_1);
|
||||||
|
|
||||||
|
let jitters: Vec<_> = points
|
||||||
|
.iter()
|
||||||
|
.map(|p| {
|
||||||
|
let x = p.x + rng.random_range(-5.0..=5.0);
|
||||||
|
let y = p.y + rng.random_range(-5.0..=5.0);
|
||||||
|
Point2d { x, y }
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let index = Spindex2d::new(&points);
|
||||||
|
let mut round = 0;
|
||||||
|
b.iter(|| todo!());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//fn reuse_index(_c: &mut Criterion) {}
|
//fn reuse_index(_c: &mut Criterion) {}
|
||||||
|
|
||||||
criterion_group!(benches, new_index);
|
criterion_group!(benches, new_index);
|
||||||
|
|
Loading…
Reference in a new issue