# time_fadd.py3 try to measure time of double A = A + B # roughly time of one floating point add # using double difference and minimum and stability import time def do_count(count, A, B): return count+1 print("time_fadd.py3 running using time.process_time()") now = time.process_time() rep = 1000 # minimum of 32 typical outer = 100000 # some big number print("rep=",rep," loop=",outer) t_prev = 0.0 A = 0.0 B = 0.1 t1 = time.process_time() for i in range(0,outer): # outer control loop count_check = 0 for j in range(0,rep): # inner control loop count_check = do_count(count_check, A, B) # end j # end i t2 = time.process_time() print("count_check=", count_check) A = 0.0 t3 = time.process_time() for i in range(0,outer): # outer measurement loop count_check = 0 for j in range(0,rep): # inner measurement loop count_check = do_count(count_check, A, B) A = A + B # item being measured, approximately FADD time # end j # end i t4 = time.process_time() print("count_check=", count_check) tmeas = (t4-t3) - (t2-t1) # the double difference print("time measured", tmeas) fadd_time = tmeas/rep fadd_time = fadd_time/outer print("fadd_time=", fadd_time," seconds") print((1.0/fadd_time)," fadd per second") print(" ") print("time_fadd.py3 finished") # end time_fadd.py3