-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
55 lines (44 loc) · 1.39 KB
/
Copy pathmain.rs
File metadata and controls
55 lines (44 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#![feature(slicing_syntax)]
// #![feature(phase)]
// #[phase(plugin, link)] extern crate log;
use std::time;
mod quadtree;
// TODO make time work...
fn now() -> u64 { time::precise_time_ns() }
macro_rules! benchmark(
($what: expr) => {
{
let start_time = now();
let ret = $what;
let end_time = now();
(ret, end_time - start_time)
}
}
);
fn main() {
use quadtree::{Quadtree, Point};
use std::rand::distributions::{IndependentSample, Range};
use std::rand::Rng;
let args = std::os::args();
let n = match &*args {
[_, ref a, ..] => match a[].parse::<u32>() {
Some(n) => n,
_ => {
println!("enter a positive integer");
return
}
},
_ => 1000
};
let mut tree: Quadtree<i32> = Quadtree::new((0.0, 0.0), 1.0, 1.0);
let mut rng = std::rand::thread_rng();
let dist = Range::new(-0.5, 0.5);
let points = (1..n).map(|_| -> (Point, i32) {
let p = (dist.ind_sample(&mut rng), dist.ind_sample(&mut rng));
(p, rng.gen())
}).collect::<Vec<(Point, i32)>>();
let (_, t_insert) = benchmark!(for e in points.into_iter() { tree.push(e); });
println!("size = {}", tree.len());
println!("nodes = {}", tree.node_count());
println!("time = {} ms", t_insert as f64 / 1e6);
}