[wxPython-users] Re: Improve performance
Christopher Barker
Chris.Barker at noaa.gov
Mon Aug 28 12:02:47 PDT 2006
>>>> Could it be, that dc.DrawPolygon(P) and dc.DrawLine is so much
>>>> slower
>>> There is some additional Python specific overhead in DrawPolygon
>>> where it has to convert the Python sequence of values into a C array
>>> of wxPoints, but other than that what you are seeing in general is
>>> probably just the difference between Python and C++.
> It might be able to be made a bit more efficient, but not a whole lot.
I'm not sure that's true, and I'm glad we have an example here that
shows it. The process of converting a python list of tuples of floats
into the form DrawPolygon needs involves, for every single point:
Check that the entry in the list is a tuple.
Check that it has two elements.
Convert each element to an int, which requires figuring out what type it
is first.
How that compares in time to drawing the next segment in the polygon, I
don't know, but this example seems to show that it could be substantial.
This is what I'd like to see, and may even write the code for some day:
numpy provides a data type for a homogeneous array of numbers. wxPython
can be taught to understand the numpy array protocol. In that case, the
type checking would only have to happen once, for all the points. If
we're lucky, DrawPolygon could take a standard C array, and the pointer
to the data could be passed through without even a copy. This could be a
lot faster.
Of course, this would require numpy, but it's the way to go for this
kind of thing anyway.
The code to be messed with is:
wxPointListHelper (or something like that)
the array protocol:
http://numpy.scipy.org/array_interface.shtml
It would be great to use this interface for creating wxImages and the
like as well.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the wxpython-users
mailing list