Skip to content

Instantly share code, notes, and snippets.

@gaspart
Last active August 18, 2021 15:37
Show Gist options
  • Save gaspart/d74283cfddc1f55f895af39ebcbe76b8 to your computer and use it in GitHub Desktop.
Save gaspart/d74283cfddc1f55f895af39ebcbe76b8 to your computer and use it in GitHub Desktop.
import time
global più_o_meno, n, pi_greco
più_o_meno = 0
n = 1
pi_greco = 4 / n
start_time = time.time()
for index in range(100000000):
n += 2
if più_o_meno == 0:
pi_greco = pi_greco - 4 / n
più_o_meno = 1
else:
pi_greco = pi_greco + 4 / n
più_o_meno = 0
print(pi_greco)
print("--- %s seconds ---" % (time.time() - start_time))
@gaspart
Copy link
Author

gaspart commented Aug 18, 2021

= RESTART: C:\Users\gtorr\AppData\Local\Programs\Python\Python37\pi_greco.py =
3.1415926545880506
--- 376.8734076023102 seconds --- 1.000.000.000 iterations

= RESTART: C:\Users\gtorr\AppData\Local\Programs\Python\Python37\pi_greco.py =
3.141592663589326
--- 36.41065573692322 seconds --- 100.000.000 iterations

= RESTART: C:\Users\gtorr\AppData\Local\Programs\Python\Python37\pi_greco.py =
3.1415927535897814
--- 3.5709989070892334 seconds --- 10.000.000 iterations

= RESTART: C:\Users\gtorr\AppData\Local\Programs\Python\Python37\pi_greco.py =
3.1415936535887745
--- 0.40099549293518066 seconds --- 1.000.000 iterations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment