Skip to content

Commit b32f546

Browse files
committed
adding ratio chart
1 parent 4959522 commit b32f546

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

python-first/chart.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from test_fixtures import build_list
66

7-
TIMEIT_TIMES = 100_000
8-
LIST_SIZE = 500
7+
TIMEIT_TIMES = 100 # Increase number for smoother lines
8+
LIST_SIZE = 10000
99
POSITION_INCREMENT = 10
1010

1111
looping_times = []
@@ -74,7 +74,29 @@ def find_match_in(list_to_search, item_to_find):
7474

7575
plt.xlim([0, LIST_SIZE])
7676
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))])
78100
plt.ylabel(f"Time to complete {TIMEIT_TIMES:,} times")
79101
plt.legend()
80102

0 commit comments

Comments
 (0)