Brent Pedersen wrote:
> http://gist.github.com/198576
> 
> gives:
> 
> method: append/get
> python: 3.5361 / 1.8621
> vector: 1.8887 / 0.5865
> array : 0.3319 / 0.1467
> 
> think that's a reasonably fair test except I cheated for array.array
> on the inserts by doing a resize() and then inserting, not appending.

Actually, that is a total cheat, and not testing the right thing at all. 
(IIUC what teh OP was looking for). You've pre-allocated, so of course 
accumulating is going to be blazingly fast. I think the point of this 
was for a situation where you don't know how big it's going to get, so 
you can't pre-allocate.

> otherwise, it's _very_ slow to do the array.append() -- over 30
> seconds instead of .33

wow! that is really, really bad. Something has got to be wrong.

I've been poking into the array.array over-allocations scheme (thanks 
Robert), and it is more conservative than lists, so it may be slower, 
but that seems like too much.


> for array.array, i used the stuff attached to this ticket:
> http://trac.cython.org/cython_trac/ticket/314

That should make it speedy indeed. Have you looked at the generated C?

cdef array.array array_append(N):
     cdef int i
     pyaa = array.array('i')
     array.array_resize(pyaa, N)
     cdef array.array aa = pyaa
     for i in range(N):
         aa._i[i] = i
     return aa

I haven't poked into the code in that ticket, but something is odd. 
Maybe you need to tell Cython that aa is not only an array.array, but 
also what type it is?

-Chris





-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

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

Reply via email to