Question

I was always intrigued by Python's collections.deque object. It seems to be like a list, except that adding/deleting items in the beginning is faster than in a list.

This makes me want to replace list with deque in various places in my code where I have a list that I do left pops on. So my question: Did anyone ever benchmark deque against list in such scenarios?

Was it helpful?

Solution

I just did a quick google search, and found two sources with code and numbers:

A mailing-list post: http://coding.derkeiler.com/Archive/Python/comp.lang.python/2010-01/msg02138.html

A blog post: http://txzone.net/2010/04/python-is-x-is-better-than-y-round-1-deque-vs-list/

It looks like a list is slightly faster than a deque for most operations, but a deque destroys a list (2 orders of magnitude for a 100,000 element list) at .pop[0].

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top