Advertisement
Guest User

Untitled

a guest
Mar 24th, 2024
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | Science | 0 0
  1. import time
  2.  
  3. ITERATIONS = 1_000_000
  4. BENCHMARKS = 20;
  5.  
  6. def leibniz(iter):
  7.     n = 1
  8.     for i in range(2, iter):
  9.         n = n + ((-1.0) ** (i - 1.0)) / ((2 * i) - 1.0)
  10.     return n * 4
  11.  
  12. total_time = 0;
  13. for i in range(BENCHMARKS):
  14.     start = time.time()
  15.     result = leibniz(ITERATIONS)
  16.     end = time.time()
  17.     total_time += end - start
  18. start = time.time()
  19. print(result)
  20. print ("Average time: ", total_time / BENCHMARKS)
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement