py-tools/btree_test.py
2022-01-17 09:40:02 +01:00

41 lines
821 B
Python

from heapq import heappop, heappush
from tools.trees import MinHeap, BinarySearchTree
from tools.stopwatch import StopWatch
s = StopWatch()
h = []
for x in range(1_000_000):
heappush(h, x)
print("Heappush:", s.elapsed())
while h:
heappop(h)
print("Heappop:", s.elapsed())
s = StopWatch()
h = MinHeap()
for x in range(1_000_000):
h.add(x)
print("MinHeap.add():", s.elapsed())
while not h.empty():
h.pop()
print("MinHeap.pop():", s.elapsed())
s = StopWatch()
b = set()
for x in range(1_000_000):
b.add(x)
print("set.add():", s.elapsed())
for x in range(1_000_000):
_ = x in b
print("x in set:", s.elapsed())
s = StopWatch()
b = BinarySearchTree()
for x in range(1_000_000):
b.add(x)
print("AVL.add():", s.elapsed())
for x in range(1_000_000):
_ = x in b
print("x in AVL:", s.elapsed())