Skip to content

Instantly share code, notes, and snippets.

@arthurk
Created March 20, 2010 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arthurk/338942 to your computer and use it in GitHub Desktop.
Save arthurk/338942 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# Benchmark pop 1st element for collections.deque vs. list
import timeit
if __name__=='__main__':
number = 1
#print timeit.timeit("for v in xrange(10): c1.insert(0, v)", "c1 = []", number=number)
#print timeit.timeit("for v in xrange(10): c1.appendleft(v)", "from collections import deque; c1 = deque()", number=number)
for r in (1,10,100,1000,5000,10000,100000):
print r
print timeit.timeit("while x: x.pop(0);",
"x = list(range("+str(r)+"))",
number=number)
print timeit.timeit("while x: x.popleft();",
"from collections import deque; x = deque(range("+str(r)+"))",
number=number)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment