Paul Ramsey reported a 5x speed improvement for prepared geometries
benchmarks at
http://blog.cleverelephant.ca/2008/10/postgis-performance-prepared-geometry.html
I'm finding about 4x with the attached benchmark code (tests
containment of many small nearly circular polygons by one larger
circular polygon):
No prep: 88717.25 usec/pass
Prep: 20406.21 usec/pass
from functools import partial
import random
import timeit
from shapely.geometry import Point
from shapely.prepared import prep
# 1000 little circles scattered in a -20,-20,20,20 box
r = partial(random.uniform, -20.0, 20.0)
spots = [Point(r(), r()).buffer(0.25) for i in range(1000)]
# Evaluate their containment by a large circle centered on the same
# box
a = Point(0.0, 0.0).buffer(20.0)
# No prep
s = """
for s in spots:
t = a.contains(s)
"""
t = timeit.Timer(
stmt=s,
setup='from __main__ import a, spots'
)
print "No prep: %.2f usec/pass" % (1000000 * t.timeit(number=100)/100)
# Prep
s = """
pa = prep(a)
for s in spots:
t = pa.contains(s)
"""
t = timeit.Timer(
stmt=s,
setup='from __main__ import prep, a, spots'
)
print "Prep: %.2f usec/pass" % (1000000 * t.timeit(number=100)/100)
--
Sean
_______________________________________________
Community mailing list
[email protected]
http://lists.gispython.org/mailman/listinfo/community