Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SpeedTests
from collections import deque
import time
def timeit(method):
def timed(*args, **kw):
ts = time.time()
result = method(*args, **kw)
te = time.time()
print('{}, {}'.format(method.__name__, te-ts))
return result
return timed
COUNT = 99999
@timeit
def test_one():
result = []
for i in range(COUNT):
result.insert(0, i)
return result
@timeit
def test_two():
result = []
for i in range(COUNT):
result.append(i)
result.reverse()
return result
@timeit
def test_three():
result = deque()
for i in range(COUNT):
result.appendleft(i)
return result
a = test_one()
print()
b = test_two()
print()
c = test_three()
"""
test_one, 3.188999891281128
test_two, 0.01100015640258789
test_three, 0.009999990463256836
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.