-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiple_batches_test.py
85 lines (64 loc) · 2.85 KB
/
multiple_batches_test.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import numpy as np
from time import process_time, perf_counter
from test_scripts.utils import print_sudoku
from test_scripts.tests import test_sudoku
def multiple_batches(num_of_batches: int, use_process_time: bool) -> None:
'''
Runs the basic test <num_of_batches> times.
Calculates fastest batch, slowest batch, fastest single puzzle solve, etc.
Prints out results.
@args num_of_batches (int) : The number of batches to test
'''
script_start_time = process_time()
total_time = 0
count = 0
fastest_batch_time = 10000
slowest_batch_time = 0
fastest_time = 10000
slowest_time = 0
try:
for i in range(num_of_batches):
print(f"RUNNING BATCH {i}/{num_of_batches}", end="\r")
difficulties = ['very_easy', 'easy', 'medium', 'hard']
batch_time = 0
fastest_time_from_batch = 10000
slowest_time_from_batch = 0
for difficulty in difficulties:
sudokus = np.load(f"data/{difficulty}_puzzle.npy")
for i in range(len(sudokus)):
sudoku = sudokus[i].copy()
your_solution, time_taken = test_sudoku(sudoku, use_process_time)
batch_time += time_taken
if time_taken < fastest_time_from_batch:
fastest_time_from_batch = time_taken
if time_taken > slowest_time_from_batch:
slowest_time_from_batch = time_taken
count += 1
total_time += batch_time
# - - - - - - - - - - - - - - - - - - - #
if batch_time < fastest_batch_time:
fastest_batch_time = batch_time
if batch_time > slowest_batch_time:
slowest_batch_time = batch_time
# - - - - - - - - - - - - - - - - - - - #
if batch_time < fastest_time:
fastest_time = fastest_time_from_batch
if batch_time > slowest_time:
slowest_time = slowest_time_from_batch
except KeyboardInterrupt: pass
average_batch_time = total_time / (count/60)
average_single_time = total_time / (count)
script_end_time = process_time()
print(f'''
# - - - - - - - - - - - - - - - - - - - - - - - - - #
Solved {count} sudokus in {round(script_end_time - script_start_time, 3)} seconds.
TOTAL SOLVING TIME {total_time / 1000} s
FASTEST BATCH TIME {fastest_batch_time} ms
SLOWEST BATCH TIME {slowest_batch_time} ms
AVERAGE BATCH TIME {average_batch_time} ms
FASTEST SINGLE TIME {fastest_time} ms
SLOWEST SINGLE TIME {slowest_time} ms
AVERAGE SINGLE TIME {average_single_time} ms
Calculated using time.{"process_time" if use_process_time else "perf_counter"}()
# - - - - - - - - - - - - - - - - - - - - - - - - - #
''')