@Override
    public Neighbor<double[], E> nearest(double[] q) {
        NeighborBuilder<double[], E> neighbor = new NeighborBuilder<>();
        search(q, root, neighbor);
        neighbor.key = keys[neighbor.index];
        neighbor.value = data[neighbor.index];
        return neighbor.toNeighbor();
    }
@Test
    public void testBenchmark() throws Exception {
        System.out.println("----- Benchmark -----");

        int N = 40000;
        int scale = 100;
        int numTests = 100_000;

        double[][] coords = new double[N][3];
        for (int i = 0; i < N; i++) {
            coords[i][0] = MathEx.random() * scale;
            coords[i][1] = MathEx.random() * scale;
            coords[i][2] = MathEx.random() * scale;
        }
        KDTree<double[]> kdt = new KDTree<>(coords, coords);

        long start = System.currentTimeMillis();
        double[] q = new double[3];
        for (int i = 0; i < numTests; i++) {
            q[0] = MathEx.random() * scale;
            q[1] = MathEx.random() * scale;
            q[2] = MathEx.random() * scale;
            kdt.nearest(q);
        }

        double time = (System.currentTimeMillis() - start) / 1000.0;
        System.out.format("Benchmark: %.2fs%n", time);
        assertTrue(time < 0.25);
    }