Kurt Smith wrote:
> Hi All,
> 
> It was suggested off list that I gather some simple benchmarks
> comparing the different ways of passing a struct with a contiguous
> array pointer inside -- through a copy, through a pointer, and through
> explicit unpacking of the struct.
> 
> So far, I find almost no difference whatsoever between the 3 modes,
> which is encouraging.  If these benchmarks hold up, it means we can
> choose the 'best' way to pass Py_buffer structs around without worry
> of a speed hit.
> 
> Comments welcome.

Nice. I do have some comments to refine this:

  - Note that your "simp" vs. "unpack" are likely identical in 
assembler, so you don't need to have them both I thinkk.

  - We also want to compare Py_buffer vs. simpler formats. E.g. if you 
want to pass a simple contiguous buffer, do you pass Py_buffer or your 
"simp"?

  - Py_buffer is much larger than your simp, which could affect the 
benchmark for ptr vs. non-ptr.

  - Make sure ll is Py_ssize_t, this could affect things on 64-bit systems.

  - In Py_buffer, the shape is stored as a pointer, so you actually need 
an extra pointer dereference to get the shape: buf.shape[0] vs. simp.ll.

So the next step would be actually using the Py_buffer struct (which is 
a Cython builtin and is documented in PEP 3118), and see how Py_buffer 
(either by copy or by ptr) holds up against simp.

As Py_buffer would be filled out outside of what you do timings on, you 
don't need to fill in things besides what you need, this will suffice:

cdef Py_buffer buf
buf.shape = &sp.ll # array of lenght 1 :-)
                    # Will cause big problems if sp.ll is not Py_ssize_t!
buf.buf = sp.dta

-- 
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to