-
Notifications
You must be signed in to change notification settings - Fork 0
/
pathfinding_tests.py
106 lines (83 loc) · 2.48 KB
/
pathfinding_tests.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
"""
Test Python script to find a (possibly shortest) path as quickly as possible
from wikipedia page A to B using the wikipedia api
"""
from timeit import default_timer
from wikitas_tools import (
find_path_wordmatching,
find_path_wordmatching_parallel,
find_path_simple,
find_path_simple_parallel,
log_path,
)
TEST_SEP = "------------------------------------"
START_PAGE = "amon goth"
END_PAGE = "japan"
# Other examples
# -------------
# START_PAGE = "minami (singer)"
# END_PAGE = "Recall_election"
# END_PAGE = "flyingdog"
# -------------
def test_word_matching_parallel():
print("With word matching (multi-threaded):")
print(TEST_SEP)
try:
start_1 = default_timer()
path = find_path_wordmatching_parallel(START_PAGE, END_PAGE)
end_1 = default_timer()
dur_1 = end_1 - start_1
log_path(path)
print(f"found in {dur_1} s")
except KeyboardInterrupt:
end_1 = default_timer()
print(f"stopped at {end_1 - start_1} s")
print(TEST_SEP)
def test_word_matching():
print("With word matching (single thread):")
print(TEST_SEP)
try:
start_1 = default_timer()
path = find_path_wordmatching(START_PAGE, END_PAGE)
end_1 = default_timer()
dur_1 = end_1 - start_1
log_path(path)
print(f"found in {dur_1} s")
except KeyboardInterrupt:
end_1 = default_timer()
print(f"stopped at {end_1 - start_1} s")
print(TEST_SEP)
def test_simple_parallel():
print("With no matching (multi-threaded)")
print(TEST_SEP)
try:
start_1 = default_timer()
path = find_path_simple_parallel(START_PAGE, END_PAGE)
end_1 = default_timer()
dur_1 = end_1 - start_1
log_path(path)
print(f"found in {dur_1} s")
except KeyboardInterrupt:
end_1 = default_timer()
print(f"stopped at {end_1 - start_1} s")
print(TEST_SEP)
def test_simple():
print("With no matching (single thread)")
print(TEST_SEP)
try:
start_2 = default_timer()
path = find_path_simple(START_PAGE, END_PAGE)
end_2 = default_timer()
log_path(path)
print(f"found in {end_2 - start_2} s")
except KeyboardInterrupt:
end_2 = default_timer()
print(f"stopped at {end_2 - start_2} s")
print(TEST_SEP)
def main():
test_word_matching_parallel()
test_simple_parallel()
test_word_matching()
test_simple()
if __name__ == "__main__":
main()