I want to time this searching algorithm using something I found on the internet
L=[8,2,1,111,8,3,4,6,5,7,10,9,12,11]
v=10
def searchlinear(L, v):
i= 0
for value in L:
if value == v:
return i
i+= 1
return len(L)
from random import randint
from timeit import repeat
def run_algorithm(algorithm, array):
setup_code = f"from __main__ import {algorithm}" \
if algorithm != "sorted" else ""
stmt = f"{algorithm}({array})"
times = repeat(setup=setup_code, stmt=stmt, repeat=3, number=10)
print(f"Algorithm: {algorithm}. Minimum execution time: {min(times)}")
ARRAY_LENGTH = len(L)
array = [randint(0, 1000) for i in range(ARRAY_LENGTH)]
run_algorithm(algorithm="searchlinear", array=array)
Somehow, it shows up this error:
TypeError: searchlinear() missing 1 required positional argument: 'v'
I feel like I have to remove the v
argument in my function, but I need that for it to work. Any tips?