-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmath_test.py
More file actions
27 lines (24 loc) · 757 Bytes
/
math_test.py
File metadata and controls
27 lines (24 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# In a new file, e.g., math_test.py
import time
def calculate_pi(n_terms: int):
"""
A numerically-intensive function that is a perfect
candidate for Numba.
"""
numerator = 4.0
denominator = 1.0
pi = 0.0
# This loop with floating-point math is a strong signal.
for _ in range(n_terms):
pi += numerator / denominator
denominator += 2.0
pi -= numerator / denominator
denominator += 2.0
return pi
if __name__ == "__main__":
start = time.time()
# Use a large number to make the work significant
result = calculate_pi(50_000_000)
end = time.time()
print(f"Pi calculation result: {result}")
print(f"Time taken: {end - start:.4f} seconds")