It might be preferable to use a non-recursive binary search as the recursive one actually builds new sub-arrays in the recursion steps. The following simply resets indices.
defBinarySearch(array_like,target):hi=len(array_like)low=0whilelow<hi-1:# current sub-array is array_like[lo:hi]iftarget<array_like[(low+hi)//2]:hi=(low+hi)//2else:low=(low+hi)//2returntarget==array_like[low]
Functions to time runs
This function takes two parameter N, the number of items in the list, and M the number of repititions for this N. It is good to repeat so as to smooth out some of the noise in the system.