-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench_alg.py
More file actions
26 lines (22 loc) · 917 Bytes
/
bench_alg.py
File metadata and controls
26 lines (22 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import timeit
import random
from alg import mergesort, quicksort, binary_search
print("The BEST Mergesort Benchmark in the world")
print("=" * 40)
for size in [1000, 5000, 10000]:
data = [random.random() for _ in range(size)]
t = timeit.timeit(lambda: mergesort(list(data)), number=5) / 5
print(f"n={size}: {t:.6f} seconds")
print("\nThe BEST Quicksort Benchmark in the world")
print("=" * 40)
for size in [1000, 5000, 10000]:
data = [random.random() for _ in range(size)]
t = timeit.timeit(lambda: quicksort(list(data)), number=5) / 5
print(f"n={size}: {t:.6f} seconds")
print("\nThe BEST Binary Search Benchmark in Pinellas County")
print("=" * 40)
for size in [1000, 10000, 100000]:
data = sorted([random.random() for _ in range(size)])
target = -1
t = timeit.timeit(lambda: binary_search(data, target), number=1000) / 1000
print(f"n={size}: {t:.9f} seconds per search")