33 lines
780 B
Python
33 lines
780 B
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)
|
||
|
|
||
|
points = {util.gen_point(-100, 100) for i in range(5_000)}
|
||
|
|
||
|
# Sanity check
|
||
|
graham = set(graham_scan(points))
|
||
|
gift = set(rapper(points))
|
||
|
quick = quick_hull(points)
|
||
|
mbch = set.union(mbc(points))
|
||
|
assert gift == graham == quick == 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,)))
|