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
|
public class Speed
{
public static void measure(Point2D p, KdTree k0)
{
Point2D np;
long t0;
long d0;
t0 = System.nanoTime();
np = k0.nearest(p);
d0 = System.nanoTime() - t0;
StdOut.printf("Nearest Point: %s => %s %.3f [ms]\n", p, np, d0/1000.0);
}
public static void main(String[] args)
{
String filename = args[0];
In in = new In(filename);
KdTree kdtree = new KdTree();
while (!in.isEmpty()) {
double x = in.readDouble();
double y = in.readDouble();
Point2D p = new Point2D(x, y);
kdtree.insert(p);
}
measure(new Point2D(0.5, 0.5), kdtree);
measure(new Point2D(0.5, 0.5), kdtree);
measure(new Point2D(0.3, 0.5), kdtree);
measure(new Point2D(0.3, 0.5), kdtree);
measure(new Point2D(0.5, 0.3), kdtree);
measure(new Point2D(0.5, 0.3), kdtree);
measure(new Point2D(0.2, 0.7), kdtree);
measure(new Point2D(0.2, 0.7), kdtree);
measure(new Point2D(0.1, 0.8), kdtree);
measure(new Point2D(0.1, 0.8), kdtree);
}
}
|