Skip to content
Snippets Groups Projects
Commit 4cab2b8d authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

wip

parent f52d6470
No related branches found
No related tags found
No related merge requests found
#
# numpi.py
# Neil Gershenfeld 1/23/17
# calculation of pi by a numpy sum
# pi = 3.14159265358979323846
#
from numpy import *
import time
NPTS = 10000000
a = 0.5
b = 0.75
c = 0.25
start_time = time.time()
i = arange(1,(NPTS+1),dtype=float64)
pi = sum(0.5/((i-0.75)*(i-.25)))
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)
#
# pi.py
# Neil Gershenfeld 1/23/17
# calculation of pi by a scalar sum
# pi = 3.14159265358979323846
#
import time
NPTS = 10000000
a = 0.5
b = 0.75
c = 0.25
pi = 0
start_time = time.time()
for i in range(1,(NPTS+1)):
pi += a/((i-b)*(i-c))
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment