Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- list and deque performance tester,
- Evan @ UC Davis
- """"
- from collections import deque
- from timeit import timeit
- def moveStackList(n):
- list0 = []
- i = 0
- while i < n:
- list0.append(i)
- i += 1
- while i > 1:
- list0.pop()
- i -= 1
- def moveStackDeque(n):
- list0 = deque()
- i = 0
- while i < n:
- list0.append(i)
- i += 1
- while i > 1:
- list0.pop()
- i -= 1
- def moveStackDequeLeft(n):
- list0 = deque()
- i = 0
- while i < n:
- list0.appendleft(i)
- i += 1
- while i > 1:
- list0.popleft()
- i -= 1
- def moveStackDequeHeterogenous(n):
- list0 = deque()
- i = 0
- while i < n:
- list0.appendleft(i)
- i += 1
- while i > 1:
- list0.popleft()
- i -= 1
- if __name__ == "__main__":
- listLength = 5000000
- iterations = 1
- timeListPop = timeit(lambda: moveStackList(listLength), number=iterations)
- timeDequePop = timeit(lambda: moveStackDeque(listLength), number=iterations)
- timeDequeLeft = timeit(lambda: moveStackDequeLeft(listLength), number=iterations)
- timeDequeHetero = timeit(lambda: moveStackDequeHeterogenous(listLength), number=iterations)
- print("for len={} and iter = {} list pop = {}".format(listLength, iterations, timeListPop))
- print("for len={} and iter = {} deque pop = {}".format(listLength, iterations, timeDequePop))
- print("for len={} and iter = {} deqye popL = {}".format(listLength, iterations, timeDequeLeft))
- print("for len={} and iter = {} deqye popH = {}".format(listLength, iterations, timeDequeHetero))
Advertisement
Add Comment
Please, Sign In to add comment