Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow K-d tree implementation #12

Closed
hoerup opened this issue Oct 7, 2015 · 2 comments
Closed

Slow K-d tree implementation #12

hoerup opened this issue Oct 7, 2015 · 2 comments

Comments

@hoerup
Copy link

hoerup commented Oct 7, 2015

Just wanted to let you know that your K-d tree implementation is very very slow compared to eg the one from https://github.com/AReallyGoodName/OfflineReverseGeocode

@hoerup hoerup changed the title K-d tree implementation Slow K-d tree implementation Oct 7, 2015
@phishman3579
Copy link
Owner

From the readme of this site "The code isn't overly-optimized but is written to be correct and readable."

In other words, I know. The code is meant to be more readable than performant.

@phishman3579
Copy link
Owner

@hoerup I did a quick test and I am seeing similar performance between the two implementations with my implementation quite a bit quicker than Geocode at nearest neighbor search. Can you show me what you did to test the performance?

Data Structure (25600 items) Add time NNS time
My KdTree 39.58 ms 70.43 ms
GeoCode KdTree 35.69 ms 243.15 ms

Testing code below...

my kd tree construction time.

        long beforeAddTime = System.nanoTime();
        KdTree<KdTree.XYZPoint> tree = new KdTree<KdTree.XYZPoint>(points, 2); // 2 since we only care about two dimensions (x,y) 
        long afterAddTime = System.nanoTime();

Geocode construction time

        long beforeAddTime = System.nanoTime();
        KDTree<XYZPoint> tree = new KDTree<XYZPoint>(points); 
        long afterAddTime = System.nanoTime();

My NNS time:

        long beforeContainsTime = System.nanoTime();
        for (KdTree.XYZPoint p : points) {
            //boolean r = tree.contains(p);
            Collection<KdTree.XYZPoint> r = tree.nearestNeighbourSearch(1, p);
            assertTrue("Point not found.", p, tree, (r.size()==1 && r.iterator().next().equals(p)));
        }
        long afterContainsTime = System.nanoTime();

GeoCode NNS time:

        long beforeContainsTime = System.nanoTime();
        for (XYZPoint p : points) {
            XYZPoint r = tree.findNearest(p);
            assertTrue("Point not found.", p, tree, r.equals(p));
        }
        long afterContainsTime = System.nanoTime();

All times measured via ((after-before)/points)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants