[Image-SIG] Comparison of PIL and GD speed for setting pixels through python

John Barratt jb at langarson.com.au
Mon Feb 5 11:22:09 CET 2007


Well after some digging through the PIL source code after the prompting 
from Douglas, and some tinkering with the python C interface, I have 
implemented a C based version of the core pixel setting loop using PIL 
objects.  I have also added 'reference' versions using plain python, 
setting an integer value in the loop, and setting an integer 2D array in 
a loop.

The short of this is that a PIL implementation with C goes faster for 
larger images (1024x1024), and faster almost overall if you only 
consider time to actually set the pixels, and not image creation time as 
well.

Fredrik, do you think it would be possible to have a standard API call 
in PIL that could cleanly & reliably expose the core C pixel data array 
for use within C (through say ctypes, or back through the python-c api) 
for optimisations like this?

The full breakdown of results, and new source code with the PIL/c 
implementation can be found here :

http://www.langarson.com.au/blog/?p=13

I think that has about exhausted the possible combinations to test, but 
if anyone has any other suggestions, please let me know.  Also if anyone 
has any ideas as to why the PIL/raw/c version should go so much faster 
than the gd/raw/c version I would be interested to know, as the core 
looping code is basically identical...

Cheers,

JB.

-- 
John Barratt - www.langarson.com.au
          Python, Zope, GIS, Weather


More information about the Image-SIG mailing list