I am trying to make a function to measure the execution time of Big O algorithms.
I have made a list with the names of the functions, and a list of n values, which are to be given to the function. I have also prepared a 2D matrix for the results.
But I get an error when running the code - argument after * must be an iterable, not int
import time
def o1(n):
return 1+1
def olog(n):
while n>0:
1+1
n//=2
return n
def on(n):
while n>0:
1+1
n-=1
return n
nlst=[10**2, 10**3 , 10**4 , 10**5 ]
algorithms=[ o1 , olog, on ]
def measure(nameF, n):
begin = time.time()
nameF(*n)
end = time.time()
res=round(end-begin,4)
return res
for a in range( len (algorithms) ):
for n in range(1 , len (nlst) + 1 ):
rlst[a][n] = measure( algorithms[a] , nlst[n-1] )
rlst=[["o1",0,0,0,0],
["olog",0,0,0,0],
["on",0,0,0,0]]
for x in rlst:
print (x)
*nsupposed to do? What are you trying to multiply? Or, if you aren't trying to multiply, what arguments are you trying to unpack?