Browse files

First benchmarks incorporated

  • Loading branch information...
1 parent cfd03d4 commit 40b2a473273c01554b7b977acff9e23ea06ce11c @patvarilly committed Sep 5, 2012
Showing with 90 additions and 0 deletions.
  1. +1 −0 scipy/spatial/__init__.py
  2. +88 −0 scipy/spatial/benchmarks/bench_ckdtree.py
  3. +1 −0 scipy/spatial/setup.py
View
1 scipy/spatial/__init__.py
@@ -32,3 +32,4 @@
import distance
from numpy.testing import Tester
test = Tester().test
+bench = Tester().bench
View
88 scipy/spatial/benchmarks/bench_ckdtree.py
@@ -0,0 +1,88 @@
+import sys
+from numpy.testing import *
+from scipy.spatial import cKDTree, KDTree
+import numpy as np
+
+class TestBuild(TestCase):
+
+ def bench_build(self):
+ print
+ print ' Constructing kd-tree'
+ print '====================================='
+ print ' dim | # points | KDTree | cKDTree '
+
+ for (m, n, repeat) in [(3,10000,3), (8,10000,3), (16,10000,3)]:
+ print '%4s | %7s ' % (m, n),
+ sys.stdout.flush()
+
+ data = np.concatenate((np.random.randn(n//2,m),
+ np.random.randn(n-n//2,m)+np.ones(m)))
+
+ print '| %6.3fs ' % (measure('T1 = KDTree(data)', repeat) / repeat),
+ sys.stdout.flush()
+ print '| %6.3fs' % (measure('T2 = cKDTree(data)', repeat) / repeat),
+ sys.stdout.flush()
+ print ''
+
+class TestQuery(TestCase):
+
+ def bench_query(self):
+ print
+ print ' Querying kd-tree'
+ print '==============================================================='
+ print ' dim | # points | # queries | KDTree | cKDTree | flat cKDTree'
+
+ for (m, n, r, repeat) in [(3,10000,1000,3),
+ (8,10000,1000,3),
+ (16,10000,1000,3)]:
+ print '%4s | %8s | %8s ' % (m, n, r),
+ sys.stdout.flush()
+
+ data = np.concatenate((np.random.randn(n//2,m),
+ np.random.randn(n-n//2,m)+np.ones(m)))
+ queries = np.concatenate((np.random.randn(r//2,m),
+ np.random.randn(r-r//2,m)+np.ones(m)))
+
+ T1 = KDTree(data)
+ T2 = cKDTree(data)
+ T3 = cKDTree(data,leafsize=n)
+ print '| %6.3fs ' % (measure('T1.query(queries)', 1) / 1),
+ sys.stdout.flush()
+ print '| %6.3fs' % (measure('T2.query(queries)', repeat) / repeat),
+ sys.stdout.flush()
+ print '| %6.3fs' % (measure('T3.query(queries)', repeat) / repeat),
+ sys.stdout.flush()
+ print ''
+
+class TestQueryBallPoint(TestCase):
+ def bench_query_ball_point(self):
+ print
+ print ' Query ball point kd-tree'
+ print '==============================================================='
+ print ' dim | # points | # queries | probe radius | KDTree | cKDTree | flat cKDTree'
+
+ for (m, n, r, repeat) in [(3,10000,1000,3)]:#,
+# (8,10000,1000,3),
+# (16,10000,1000,3)]:
+ for probe_radius in (0.2, 0.5):
+ print '%4s | %8s | %9s | %11.1f ' % (m, n, r, probe_radius),
+ sys.stdout.flush()
+
+ data = np.concatenate((np.random.randn(n//2,m),
+ np.random.randn(n-n//2,m)+np.ones(m)))
+ queries = np.concatenate((np.random.randn(r//2,m),
+ np.random.randn(r-r//2,m)+np.ones(m)))
+
+ T1 = KDTree(data)
+ T2 = cKDTree(data)
+ T3 = cKDTree(data,leafsize=n)
+ print '| %6.3fs ' % (measure('T1.query_ball_point(queries, probe_radius)', 1) / 1),
+ sys.stdout.flush()
+ print '| %6.3fs' % (measure('T2.query_ball_point(queries, probe_radius)', repeat) / repeat),
+ sys.stdout.flush()
+ print '| %6.3fs' % (measure('T3.query_ball_point(queries, probe_radius)', repeat) / repeat),
+ sys.stdout.flush()
+ print ''
+
+if __name__ == "__main__":
+ run_module_suite()
View
1 scipy/spatial/setup.py
@@ -10,6 +10,7 @@ def configuration(parent_package = '', top_path = None):
config = Configuration('spatial', parent_package, top_path)
config.add_data_dir('tests')
+ config.add_data_dir('benchmarks')
qhull_src = ['geom2.c', 'geom.c', 'global.c', 'io.c', 'libqhull.c',
'mem.c', 'merge.c', 'poly2.c', 'poly.c', 'qset.c',

0 comments on commit 40b2a47

Please sign in to comment.