Skip to content

Instantly share code, notes, and snippets.

@raeq
Created September 5, 2020 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raeq/d95332d331ead89a695c21934d378db0 to your computer and use it in GitHub Desktop.
Save raeq/d95332d331ead89a695c21934d378db0 to your computer and use it in GitHub Desktop.
Create timings
from timeit import *
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)
results.append((i, st1 / 10, st2 / 10))
print(results)
return results
if __name__ == "__main__":
old_results = collect_results()
import numpy as np
import matplotlib.pyplot as plt
matrixDat = np.array(old_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');
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