Last active
August 29, 2015 14:25
-
-
Save vaclavcadek/68d842b788f4286ef1a8 to your computer and use it in GitHub Desktop.
Comparison of runtime behavior of three approaches: pure Python, naive NumPy and good NumPy
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
import timeit | |
normal_py_sec = timeit.timeit('sum(x*x for x in xrange(1000))', number=10000) | |
naive_np_sec = timeit.timeit('sum(na*na)', setup="import numpy as np; na=np.arange(1000)", number=10000) | |
good_np_sec = timeit.timeit('na.dot(na)', setup="import numpy as np; na=np.arange(1000)", number=10000) | |
print("Normal Python: %f sec" % normal_py_sec) | |
print("Naive NumPy: %f sec" % naive_np_sec) | |
print("Good NumPy: %f sec" % good_np_sec) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment