开发者

Are there any benchmarks showing good performance of `collections.deque`?

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 lis开发者_StackOverflow中文版t that I do left pops on. So my question: Did anyone ever benchmark deque against list in such scenarios?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜