forked from Toblerity/Fiona
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark-max.py
56 lines (47 loc) · 1.18 KB
/
benchmark-max.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import timeit
from fiona import collection
from osgeo import ogr
PATH = 'docs/data/test_uk.shp'
NAME = 'test_uk'
# Fiona
s = """
with collection(PATH, "r") as c:
for f in c:
id = f["id"]
"""
t = timeit.Timer(
stmt=s,
setup='from __main__ import collection, PATH, NAME'
)
print "Fiona 0.5"
print "%.2f usec/pass" % (1000000 * t.timeit(number=1000)/1000)
print
# OGR
s = """
source = ogr.Open(PATH)
layer = source.GetLayerByName(NAME)
schema = []
ldefn = layer.GetLayerDefn()
for n in range(ldefn.GetFieldCount()):
fdefn = ldefn.GetFieldDefn(n)
schema.append((fdefn.name, fdefn.type))
for feature in layer:
id = feature.GetFID()
props = {}
for i in range(feature.GetFieldCount()):
props[schema[i][0]] = feature.GetField(i)
coordinates = []
for part in feature.GetGeometryRef():
ring = []
for i in range(part.GetPointCount()):
xy = part.GetPoint(i)
ring.append(xy)
coordinates.append(ring)
source.Destroy()
"""
print "osgeo.ogr 1.7.2 (maximum)"
t = timeit.Timer(
stmt=s,
setup='from __main__ import ogr, PATH, NAME'
)
print "%.2f usec/pass" % (1000000 * t.timeit(number=1000)/1000)