Skip to content

Instantly share code, notes, and snippets.

@sgillies
Created April 25, 2011 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgillies/940905 to your computer and use it in GitHub Desktop.
Save sgillies/940905 to your computer and use it in GitHub Desktop.
Shapely speedups benchmarks
(gispy-lab)krusty-2:Shapely-1.2 seang$ python speedups-benchmark.py
N=10
======
Without speedups
74.75 usec/pass
With speedups
19.80 usec/pass
(gispy-lab)krusty-2:Shapely-1.2 seang$ python speedups-benchmark.py
N=100
======
Without speedups
518.01 usec/pass
With speedups
27.57 usec/pass
(gispy-lab)krusty-2:Shapely-1.2 seang$ python speedups-benchmark.py
N=1000
======
Without speedups
4939.36 usec/pass
With speedups
146.21 usec/pass
# Benchmark of olt's https://github.com/olt/shapely/tree/master/shapely/speedups
import array
import timeit
from shapely.geometry import LineString
import shapely.speedups
N = 100 # num of vertices
M = 100 # num of passes
print
print "N=%s" % N
print "======"
xs = array.array('d', [i for i in range(N)])
ys = array.array('d', [i for i in range(N)])
coords = zip(xs, ys)
s = """
line = LineString(coords)
"""
t = timeit.Timer(
stmt=s,
setup='from __main__ import coords, LineString'
)
# No speedups
shapely.speedups.disable()
print "Without speedups"
print "%.2f usec/pass" % (1000000 * t.timeit(number=M)/M)
print
# With speedups
shapely.speedups.enable()
print "With speedups"
print "%.2f usec/pass" % (1000000 * t.timeit(number=M)/M)
print
@sgillies
Copy link
Author

Without speedups, cost of creating a line is proportional to N (number coordinates). With speedups, it's a flatter function of N.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment