numbapi.py 529 Bytes
Newer Older
Neil Gershenfeld's avatar
Neil Gershenfeld committed
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
#
# numbapi.py
# Neil Gershenfeld 2/6/20
# calculation of pi by a Numba sum
# pi = 3.14159265358979323846 
#

import time
from numba import jit

NPTS = 100000000
@jit(nopython=True)
def calc():
   a = 0.5
   b = 0.75
   c = 0.25
   pi = 0
   for i in range(1,(NPTS+1)):
      pi += a/((i-b)*(i-c))
   return pi
start_time = time.time()
pi = calc()
end_time = time.time()
mflops = NPTS*5.0/(1.0e6*(end_time-start_time))
print("NPTS = %d, pi = %f"%(NPTS,pi))
print("time = %f, estimated MFlops = %f"%(end_time-start_time,mflops))