[Numpy-discussion] numarray speed - PySequence_GetItem

Sebastian Haase haase at msg.ucsf.edu
Fri Jun 25 09:50:08 CDT 2004


Hi,
The long story is that I'm looking for a good/fast graph plotting programs; so 
I found WxPyPlot (http://www.cyberus.ca/~g_will/wxPython/wxpyplot.html)
It uses wxPython and plots 25000 data points (with lines + square markers) in 
under one second - using Numeric that is. 
[the slow line in WxPyPlot is:
dc.DrawLines(self.scaled)
    where self.scaled is an array of shape (25000,2) and type Float64
]

The short story is that numarray takes maybe 10 times as long as Numeric
and I tracked the problem down into the wxPython SWIG typemap where he does 
this:

<code-sniplet  from wxPoint_LIST_helper() in helpers.cpp  from wxPython>
  wxPoint* wxPoint_LIST_helper(PyObject* source, int *count)
  { <snip>
  bool isFast = PyList_Check(source) || PyTuple_Check(source);
  <snip>
  for (x=0; x<*count; x++) {
          // Get an item: try fast way first.
          if (isFast) {
              o = PySequence_Fast_GET_ITEM(source, x);
          }
          else {
              o = PySequence_GetItem(source, x);
              if (o == NULL) {
                  goto error1;
              }
          }
</code-sniplet>


I'm not 100% sure that this is where the problem lies - is there a chance (or 
a known issue) that numarray does  PySequence_GetItem()  slower than 
Numeric ?

I just ran this again using the python profiler and 
I get this w/ numarray:
   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    1.140    1.140    1.320    1.320 gdi.py:554(DrawLines)
        1    1.250    1.250    1.520    1.520 gdi.py:792(_DrawRectangleList)
    50230    0.450    0.000    0.450    0.000 numarraycore.py:501(__del__)
and this with Numeric:
        1    0.080    0.080    0.080    0.080 gdi.py:554(DrawLines)
        1    0.090    0.090    0.090    0.090 gdi.py:792(_DrawRectangleList)


Thanks,
Sebastian Haase






More information about the Numpy-discussion mailing list