On Wed, Oct 19, 2011 at 12:42 PM, Simon King <[email protected]> wrote: > Hi Alexander and all, > > First of all, sorry that I posted twice the same - google groups > reported an error when I first tried to post. > > On 19 Okt., 19:58, Alexander Juarez <[email protected]> wrote: >> I think I found the collections.deque() to be faster that than the >> list.pop() which makes sense if the list is implemented as a linked >> list object. And the collections uses a array implementation. > > In contrast to my first tests, it meanwhile seems to me that the > L[0], PyList_GetSlice(L,1,PyList_GET_SIZE(L)) > idiom is faster than deque in my applications. Recall that this was > the fastest replacement for pop(0), if the lists are not too long > (which will probably be the case in my applications).
I have no idea why L.pop(0) is not optimized, but L.pop(<int>0) is (and the latter should be very fast). Clearly a bug in Cython, but user the latter. > After all, "collections" is Python, not Cython. > > Nevertheless, I'd still appreciate to learn a Cython replacement for > pop(0) that is fast on long lists as well. There isn't one as pop(0) on a list requires re-copying the entire contents of the list. You could use numpy arrays, where slices such as L[1:] are views. A cython-implemented linked list may perform well here as well. > I found this: > http://www.mail-archive.com/[email protected]/msg07518.html > but Sturla Molden's trick didn't work for me: Cython complained about > an incomplete type. > > Best regards, > Simon > > -- > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/sage-support > URL: http://www.sagemath.org > -- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
