Skip to content

Instantly share code, notes, and snippets.

@raeq
Created September 5, 2020 14:39
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/8a4d522586bf88a664570190c3a2a141 to your computer and use it in GitHub Desktop.
Save raeq/8a4d522586bf88a664570190c3a2a141 to your computer and use it in GitHub Desktop.
Timing data
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