Created
April 16, 2018 12:03
-
-
Save nhannguyen95/a7a89b40ff417f19d056e2248c3452f3 to your computer and use it in GitHub Desktop.
Python profiling
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 pstats, cProfile | |
def recip_square(i): | |
return 1./i**2 | |
def approx_pi(n=10000000): | |
val = 0. | |
for k in range(1,n+1): | |
val += recip_square(k) | |
return (6 * val)**.5 | |
if __name__ == '__main__': | |
cProfile.runctx("approx_pi()", globals(), locals(), "Profile.prof") | |
s = pstats.Stats("Profile.prof") | |
s.strip_dirs().sort_stats("time").print_stats() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment