|
4 | 4 |
|
5 | 5 | from test_fixtures import build_list |
6 | 6 |
|
7 | | -TIMEIT_TIMES = 100_000 |
8 | | -LIST_SIZE = 500 |
| 7 | +TIMEIT_TIMES = 100 # Increase number for smoother lines |
| 8 | +LIST_SIZE = 10000 |
9 | 9 | POSITION_INCREMENT = 10 |
10 | 10 |
|
11 | 11 | looping_times = [] |
@@ -74,7 +74,29 @@ def find_match_in(list_to_search, item_to_find): |
74 | 74 |
|
75 | 75 | plt.xlim([0, LIST_SIZE]) |
76 | 76 | plt.xlabel("Position of element to be found") |
77 | | -plt.ylim([0, max(max(looping_times), max(generator_times))]) |
| 77 | +plt.ylim([0, max(max(looping_times), max(generator_times), max(in_times))]) |
| 78 | +plt.ylabel(f"Time to complete {TIMEIT_TIMES:,} times") |
| 79 | +plt.legend() |
| 80 | + |
| 81 | +plt.show() |
| 82 | + |
| 83 | +# Ratio |
| 84 | + |
| 85 | +looping_ratio = [loop / loop for loop in looping_times] |
| 86 | +generator_ratio = [ |
| 87 | + gen / loop for gen, loop in zip(generator_times, looping_times) |
| 88 | +] |
| 89 | +in_ratio = [in_ / loop for in_, loop in zip(in_times, looping_times)] |
| 90 | + |
| 91 | +fig, ax = plt.subplots() |
| 92 | + |
| 93 | +plot = ax.plot(positions, looping_ratio, label="loop") |
| 94 | +plot = ax.plot(positions, generator_ratio, label="generator") |
| 95 | +plot = ax.plot(positions, in_ratio, label="in") |
| 96 | + |
| 97 | +plt.xlim([0, LIST_SIZE]) |
| 98 | +plt.xlabel("Position of element to be found") |
| 99 | +plt.ylim([0, max(max(looping_ratio), max(generator_ratio), max(in_ratio))]) |
78 | 100 | plt.ylabel(f"Time to complete {TIMEIT_TIMES:,} times") |
79 | 101 | plt.legend() |
80 | 102 |
|
|
0 commit comments