Hey John -
I was working on some of the color stuff, and I noticed you switched to using wx.Image_HSVtoRGB() instead of Python's built-in colorsys module.

I've tested this and the Python-based HSV/RGB conversion is actually significantly faster. I have no doubt that the raw C++ routines converting HSV to RGB are faster internally, but SWIG really slows things down. This was actually once of my "lessons learned" when doing calendar performance work: avoid calling through SWIG at all costs.

Here are the tests and results on my Windows box (Pentium M, 1.6Ghz) using our Visual Studio-based Python.

> release/RunPython.bat -m timeit -s 'import wx;hue=120' 'wx.Image.HSVtoRGB(wx.Image_HSVValue(hue/360.0, 0.5, 1.0))'
10000 loops, best of 3: 17.2 usec per loop

> release/RunPython.bat -m timeit -s 'from colorsys import hsv_to_rgb;hue=120' 'hsv_to_rgb(hue/360.0, 0.5, 1.0)'
100000 loops, best of 3: 3.55 usec per loop


Almost 5 times faster! The only problem with using hsv_to_rgb is that the numbers come back in the 0 to 1.0 range, rather than 0..255. But that is easy to fix:

> release/RunPython.bat -m timeit -s 'from colorsys import hsv_to_rgb;hue=120' 'rgb = [int(v) for v in hsv_to_rgb(hue/360.0, 0.5, 1.0)]'
10000 loops, best of 3: 6.79 usec per loop

So even with this conversion, it is more than 2.5x faster to use pure python than to keep calling through SWIG.

Alec
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Open Source Applications Foundation "chandler-dev" mailing list
http://lists.osafoundation.org/mailman/listinfo/chandler-dev

Reply via email to