Python: is X is better than Y ? Round 1, deque vs list.

This week-end, i’ve spend some time about searching how to optimize PyMT code. And done some interesting benchmark. Next days, i’ll post some of them, in order to remember which is the better solution.

For the first round: let’s test Deque from collections package VS Python List !

Code:

And the result :

Impact for PyMT: wm_pen, wm_touch.

Facebook Twitter Delicious Reddit Digg

3 thoughts on “Python: is X is better than Y ? Round 1, deque vs list.

  1. Wouldn’t it be a more accurate test if both of them empty the same way? (Although, after running it on my computer the deque still wins either way, but there’s a significant improvement using the for loop, ~4 seconds average on my machine on the deque)

  2. You’re right, i’ve discover after writing this blog post that deque is capable of len(). But we must should now that usually for a “queue” (specially in threaded environ), you can’t test len() and pop(). pop() can fail just after a test with len().

    That’s what i was testing for deque 🙂

  3. “pop” for deque and list both remove the last element of list. so in ur code

    x.pop() != q.pop(0) [x = deque and q = list], here x.pop() removes element from end and q.pop(0) remove elements from front

    instead use x.popleft()

Leave a Reply

Your email address will not be published. Required fields are marked *