Created
November 27, 2014 09:21
-
-
Save zerc/f61441211c9ee4bd7a15 to your computer and use it in GitHub Desktop.
SpeedTests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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