7

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?

Ram Rachum
  • 84,019
  • 84
  • 236
  • 374
  • Why don't you self make such benchmarks and report them here? Instead asking someone else to do them on behalf of your self? Thanks – eat Mar 19 '11 at 20:31
  • 1
    @eat he's asking if someone has already performed the benchmark, he wasn't asking YOU to do it. – Amir Rachum Mar 19 '11 at 20:37
  • 5
    @eat: Maybe someone already spent hours benchmarking deque against list in various different scenarios? Wouldn't it be better if we were all exposed to this research instead of replicating it? – Ram Rachum Mar 19 '11 at 20:43
  • Well you do have your own use cases, someone else has theirs, and rest of us do have many different ones. So basically it should more straightforward one to harness only yours than trying to understand (adapt) some one else's. So simply my point is that every programmer should be able to measure the performance of their code. Simply don't act on based some general benchmark, rather find it out your self. Thanks – eat Mar 19 '11 at 21:00

1 Answers1

3

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].

Buttons840
  • 9,239
  • 15
  • 58
  • 85
  • Before Michael's edit, this was a borderline [link-only answer](http://meta.stackexchange.com/q/8231/213671). In the future, expand your answer to include as much information here, and use links only for reference. – gunr2171 Apr 19 '15 at 20:08