[wxPython] Re: Patch to wxPoint_LIST_Helper and friends

Hi All,

I like the idea of being able to use Numeric Arrays for plotting, but I am
concerned about the cost it will have in terms of performace for some of my
code. I switched from tkinter to wxpython about a year and a half ago
because tkinter didnt have the performance that I needed for plotting large
numbers of lines to the screen. (See some benchmarks around that time for a
comparison of the two.) I need to have a very fast refresh rate (for
oscilloscope applications) therefore performance is important to me. A 30%
hit in performace would not be welcome.

Is there some other way of achieving the Numeric goal without impacting
existing performance?

Regards,

Gordon Williams

···

----------------------------------------------------------------------------
--------------
PERFORMANCE:

There was some question about how using the general sequence protocol would
affect speed. As shown by the data below, there is a significant impact: for
the best case (a list of tuples of ints) things slowed down by about 50%.
However the speed of plotting Numeric arrays is improved by over a factor of
four. The slowdown for the lists of tuples cases can be eliminated by adding
special cases to the code, but at the expense of complexity. I suspect that
most applications that are plotting large numbers of points use Numeric, so
I think that the first and fourth rows in the table below are most
important. (This is obviously a somewhat biased view). I personally don't
think the complexity that the fast version of the codes add is worth the
speed gain, so the patch is against the simpler new version. NEW-FAST is
included with this message as a separate file, but it has not been tested or
even scrutinized very much.

Table: Times for plotting 50,000 points using PlotLines (see
testwxpatch.py):

TEST NEW NEW-FAST OLD
array: 0.134961007614 0.134145037987
(0.634264634192)
[(x,y)]: 0.104322197374 0.0881805369118
0.0870843082012
[[x,y]]: 0.108765723018 0.103665577608
(0.613360413125)
intarray: 0.086473224949 0.0866711830694
(0.626794075783)
[(intx,inty)]: 0.0548769187145 0.0394333916741
0.0387480531744
[[intx,inty]]: 0.0564195728787 0.0531457489709
(0.462688805421)

Values in parentheses were computed by first using map(tuple, data) since
these wouldn't work directly with the old version.

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

Hi Gordon et al,

I like the idea of being able to use Numeric Arrays for plotting, but I am
concerned about the cost it will have in terms of performace for some of

my

code. I switched from tkinter to wxpython about a year and a half ago
because tkinter didnt have the performance that I needed for plotting

large

numbers of lines to the screen. (See some benchmarks around that time for

a

comparison of the two.) I need to have a very fast refresh rate (for
oscilloscope applications) therefore performance is important to me. A

30%

hit in performace would not be welcome.

And your passing in lists of tuples for that? Drat! I guess that means I'm
gonna have to this the hard way.

Is there some other way of achieving the Numeric goal without impacting
existing performance?

Yes, see the figures for NEW-FAST. The speed is almost exactly the same as
the old speed for the cases they overlap. Unfortunately, this doubles the
length of wxPoint_LIST_helper function and makes it more messy, so I was
hoping to be able to use the simpler version. In other words I was hoping
nobody was plotting large lists of tuples.

I'll go back to the drawing board and see if I can clean up the NEW-FAST
code a bit and resubmit a patch.

Regards,

-tim

···

Regards,

Gordon Williams

--------------------------------------------------------------------------

--

--------------
PERFORMANCE:

There was some question about how using the general sequence protocol

would

affect speed. As shown by the data below, there is a significant impact:

for

the best case (a list of tuples of ints) things slowed down by about 50%.
However the speed of plotting Numeric arrays is improved by over a factor

of

four. The slowdown for the lists of tuples cases can be eliminated by

adding

special cases to the code, but at the expense of complexity. I suspect

that

most applications that are plotting large numbers of points use Numeric,

so

I think that the first and fourth rows in the table below are most
important. (This is obviously a somewhat biased view). I personally don't
think the complexity that the fast version of the codes add is worth the
speed gain, so the patch is against the simpler new version. NEW-FAST is
included with this message as a separate file, but it has not been tested

or

even scrutinized very much.

Table: Times for plotting 50,000 points using PlotLines (see
testwxpatch.py):

TEST NEW NEW-FAST

OLD

array: 0.134961007614 0.134145037987
(0.634264634192)
[(x,y)]: 0.104322197374 0.0881805369118
0.0870843082012
[[x,y]]: 0.108765723018 0.103665577608
(0.613360413125)
intarray: 0.086473224949 0.0866711830694
(0.626794075783)
[(intx,inty)]: 0.0548769187145 0.0394333916741
0.0387480531744
[[intx,inty]]: 0.0564195728787 0.0531457489709
(0.462688805421)

Values in parentheses were computed by first using map(tuple, data) since
these wouldn't work directly with the old version.

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

Gordon Williams wrote:

I like the idea of being able to use Numeric Arrays for plotting, but I am
concerned about the cost it will have in terms of performace for some of my
code. I switched from tkinter to wxpython about a year and a half ago
because tkinter didnt have the performance that I needed for plotting large
numbers of lines to the screen. (See some benchmarks around that time for a
comparison of the two.) I need to have a very fast refresh rate (for
oscilloscope applications) therefore performance is important to me. A 30%
hit in performace would not be welcome.

Is there some other way of achieving the Numeric goal without impacting
existing performance?

Gordon,

I have to say that I am very surprised that you are working with a large
data set in a performance critical application without using Numeric. I
don't know any of the details of your project, but I'd be surprised if
you couldn't get substantial performance benefits from using Numeric
outside of your drawing code anyway, so that Tim's approach might well
work for you as well.

I have to say a agree with Tim, I was surprised to see that someone was
working with a large set of numbers would not be using Numeric. Have you
considered it?

This is not to say that an optimised-for-many-cases
wxPoint_SEQUENCE_Helper wouldn't be a ggod thing, so if Tim is willing
to do it, great!

Another note about drawing optimizations:

What Gordon and Tim are talking about is fast use of the dc.DrawLines
function, which, unfortunately, is a bit of a misnomer. It is really a
function that draws a single polyline. It, and DrawPolygon, are the only
DC drawing functions that take a list of points, and are the only ones
for which this optimisation matters. For those of us that often need to
draw a LOT of polygons, or polylines, or points (esspecially points)
using the dc functions from Python is SLOW. I never noticed that the
conversion from a Numeric array to a list of points took very long,
because the time it takes to loop though 1000 points and call
dc.DrawPoint 1000 times is far greater.

For quite a while now, I have been intending to try to write an expanded
wrapper around the dcs that would provide a set of function like
dc.DrawPoints (note the plural, also dc.DrawPolygons, dc.DrawRectangles,
etc.) that would take a sequence of point coordinates and either a
single Pen and Brush, or a sequence of pens and brushes, and do the loop
through them in C++, rather than Python. THis should speed up the
drawing of many objects a lot, which I critically need to do.

There are two reasons I havn't done this yet:
1) I am short on time (like everyone else)
2) I am pretty poorly qualified to do this. I am just learning C++, and
as Tim makes clear there are a lot details that have to be gotten right
to prevent memory leaks and such.

So: what I am asking now is anyone else thinks this would be useful, and
want to contribute their ideas to the design. Or, even better, help me
figure out how to write the code.

-Chris

···

--
Christopher Barker,
Ph.D.
cbarker@jps.net --- --- ---
http://www.jps.net/cbarker -----@@ -----@@ -----@@
                                   ------@@@ ------@@@ ------@@@
Water Resources Engineering ------ @ ------ @ ------ @
Coastal and Fluvial Hydrodynamics ------- --------- --------
------------------------------------------------------------------------
------------------------------------------------------------------------

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users