from y_r04_1_triangle import nirt_v1 as nirt_v1
from y_r04_2_triangle import nirt_v2 as nirt_v2
from y_r04_3_triangle import nirt_v3 as nirt_v3
from y_r04_4_triangle import nirt_v4 as nirt_v4
from y_r04_5_triangle import nirt_v5 as nirt_v5
import time
def elapsed(expression,number=1):
''' computes elapsed time for executing code
number of times (default is 1 time). expression should
be a string representing a Python expression. '''
t1=time.clock()
for i in range(number):
eval(expression)
t2=time.clock()
return t2-t1
# measure time
lst1 = [0]*5
lst2 = [0]*5
p = 240
for v in range(1,6):
lst1[v-1] = elapsed("nirt_v"+str(v)+"("+str(p)+")")
print("version",v,"p =",p,":",lst1[v-1],"secs")
print("")
p = 480
for v in range(1,6):
lst2[v-1] = elapsed("nirt_v"+str(v)+"("+str(p)+")")
print("version",v,"p =",p,":",lst2[v-1],"secs")
print("")
for v in range(1,6):
print("version",v,"slowed down by:",lst2[v-1]/lst1[v-1])
# when p increases by two,
# and for large enough p (so that asymptotic computations are valid),
# cubic code should take ~2**3 more time
# quadratic codes should take ~2**2 more time
# linear code should take ~2 more time
# if we use larger p's,
# the running time ratios become more similar to the predicted asymptotic ratios,
# since the effect of the constants become negligible.