Open ivan-pi opened 3 years ago
The base results for the kd-tree (compiled with -O3) by Matthew Kennel are:
$ ./time
Dimension = 3
Tree build (s): 3.41600017E-03
Tree query (s): 1.05800014E-03
Dimension = 8
Tree build (s): 4.14900016E-03
Tree query (s): 1.39079997E-02
Dimension = 16
Tree build (s): 5.63300028E-03
Tree query (s): 0.218334988
Results for fortran-kdtree:
Dimension = 3
Tree build (s): 1.72240008E-02
Tree query (s): 2.98899971E-03
Dimension = 8
Tree build (s): 1.78660005E-02
Tree query (s): 6.87720031E-02
Dimension = 16
Tree build (s): 2.24789977E-02
Tree query (s): 1.19430590
Results for coretran:
$ ./kdtree_benchmark_coretran
Dimension = 3
Tree build (s): 9.62999929E-03
Tree query (s): 5.50929978E-02
Dimension = 8
Tree build (s): 5.86700439E-03
Tree query (s): 0.254123986
Dimension = 16
Tree build (s): 1.20519996E-02
Tree query (s): 0.819300950
I've added the following codeblock (in my local copies) to make sure all trees are querying the same data set:
call random_seed(size=s)
allocate(seed(s))
seed = 1234
call random_seed(put=seed)
Results:
kdtree2 (current repo)
$ ./kdtree2_benchmark
Dimension = 3
Tree build (s): 4.27499972E-03
Tree query (s): 1.53200049E-03
Dimension = 8
Tree build (s): 5.56499884E-03
Tree query (s): 1.18070003E-02
Dimension = 16
Tree build (s): 4.06300090E-03
Tree query (s): 0.185646996
coretran by @leonfoks
$ ./kdtree_benchmark_coretran
Dimension = 3
Tree build (s): 5.02100028E-03
Tree query (s): 6.64850026E-02
Dimension = 8
Tree build (s): 5.93599677E-03
Tree query (s): 0.263607979
Dimension = 16
Tree build (s): 9.59497690E-03
Tree query (s): 0.799394011
fortran-kdtree by @dongli
$ ./kdtree_benchmark
Dimension = 3
Tree build (s): 2.06680000E-02
Tree query (s): 3.00700031E-03
Dimension = 8
Tree build (s): 1.71739999E-02
Tree query (s): 6.86710030E-02
Dimension = 16
Tree build (s): 2.13799998E-02
Tree query (s): 1.15235996
(Edit: I realized later, that kdtree2 was built in single precision, while the other two were using double. However, rerunning the base result in double precision did not appear to change the runtime).
(Edit2: I noticed that coretran results are slower for the trees in 3 and 8 dimensions. This might be related to the fact that coretran uses the opposite memory arrangement than the other two codes).
I was able to get my FLANN bindings working again (but only for float
...).
To install FLANN with apt: sudo apt-get install libflann-dev
Compile the Fortran executable: gfortran -O3 flann.f90 kdtree_benchmark_flann.f90 -lflann
flann.f90.txt
Results:
$ ./a.out
Dimension = 3
Tree build (s): 2.71600019E-03
Tree query (s): 1.50110004E-02
Dimension = 8
Tree build (s): 1.25530008E-02
Tree query (s): 1.56069994E-02
Dimension = 16
Tree build (s): 9.34499875E-03
Tree query (s): 0.197361007
Timings are close to Fortran kdtree2 :smirk:.
Very interesting comparison! For fortran-kdtree
, I haven't optimized it intensively. It looks I have more work to do. : P
While the results of comparing vs Scipy are encouraging, before I go too far with the refactoring it would be smart to benchmark against other Fortran kd-trees:
and potentially also againt some well known C/C++ libraries: