BerGeo/h2/tmptest.py
2018-10-11 15:54:52 +02:00

43 lines
1.0 KiB
Python

import random
from time import time
import util
from gift_wrapper import rapper
from graham import graham_scan
from mbc import mbc
from quick_hull import quick_hull
#random.seed(1337_420)
while True:
print("="*100)
points = {util.gen_point(-100, 100) for i in range(100)}
print("Points:", sorted(points))
# Sanity check
graham = set(graham_scan(points))
gift = set(rapper(points))
quick = quick_hull(points)
mbch = set.union(mbc(points))
print("graham:", sorted(graham))
print("gift :", sorted(gift))
print("quick :", sorted(quick))
print("mbch :", sorted(mbch))
if not gift == graham == quick == mbch:
util.display(points=points, hull=mbch)
def time_it(f: callable, args: tuple = (), iterations=20):
start = time()
for i in range(iterations):
f(*args)
return time() - start
print("graham:", time_it(graham_scan, args=(points,)))
print("gift:", time_it(rapper, args=(points,)))
print("quick:", time_it(quick_hull, args=(points,)))
print("mbch:", time_it(mbc, args=(points,)))