OGR, Ctypes, and Cython, Again
My previous benchmarks were made using the original recipe ogr.py module from GDAL 1.3.2. I saw some numbers that compelled me to try to new Python bindings from GDAL 1.4.3. Here are the new results (same benchmark code) on that same machine:
sean@lenny:~/Projects$ python ogre_benchmark.py Refinery (with ctypes) 4994133.40 usec/pass Ogre (Cython/Pyrex) 593522.91 usec/pass ogr.py (next generation bindings) 594103.50 usec/pass
Howard Butler's new bindings for 1.4.3 are about 15 times faster at this task than the old bindings for 1.3.2. I had no idea that performance was so improved. That's great news for people who want to keep using programs based on ogr.py. You'll notice that Ogre itself is 15% faster today thanks to conversion of some Python statements to C. I feel like I'm starting to know my way around Pyrex and Cython and can squeeze out some higher performance yet.
Ogre is as quick as the latest and greatest ogr.py, and does more work at the same price. For each collection iteration, Ogre is marshaling the OGR layer definitions into a collection schema, and marshals every OGR feature into a GeoJSON-like data structure using the collection object hook. Even with that overhead, Ogre is as fast as ogr.py. Remove the extras and it compares to ogr.py like this:
sean@lenny:~/Projects$ python ogre_benchmark.py Ogre (no auto schema, no object hook) 443894.31 usec/pass ogr.py (next generation bindings) 588154.32 usec/pass
That's 25% faster. Not bad at all, considering that better performance was never my motivation.