Created
September 5, 2020 14:39
-
-
Save raeq/8a4d522586bf88a664570190c3a2a141 to your computer and use it in GitHub Desktop.
Timing data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def collect_results(): | |
results = [] | |
for i in range(1000, 2000001, 100000): | |
f = "fast_doubling_fibonacci_recursive" | |
t1 = Timer(f"{f}({i})", | |
f"from __main__ import {f}") | |
st1 = t1.timeit(number=10) | |
f = "matrix_fibonacci" | |
t2 = Timer(f"{f}({i})", | |
f"from __main__ import {f}") | |
st2 = t2.timeit(number=10) | |
f = "fibonacci_djikstra" | |
t3 = Timer(f"{f}({i})", | |
f"from __main__ import {f}") | |
st3 = t3.timeit(number=10) | |
results.append((i, st1 / 10, st2 / 10, st3 / 10)) | |
print(results) | |
return results | |
if __name__ == "__main__": | |
matrixDat = np.array(collect_results()) | |
print (matrixDat) | |
plt.plot(matrixDat[:, 0], matrixDat[:, 1], 'o', color='red', label='fast_doubling_fibonacci_recursive'); | |
plt.plot(matrixDat[:, 0], matrixDat[:, 2], '+', color='blue', label='matrix_fibonacci'); | |
plt.plot(matrixDat[:, 0], matrixDat[:, 3], 'D', color='black', label='fibonacci_djikstra'); | |
plt.ylabel("Fibonacci(n)") | |
plt.xlabel("Duration(s)") | |
leg = plt.legend(numpoints=1) | |
plt.savefig('my_plot.png') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment