Skip to content

Instantly share code, notes, and snippets.

@andreyfedoseev
Created December 6, 2014 14:45
Show Gist options
  • Save andreyfedoseev/25099bf6474e2d45f0ed to your computer and use it in GitHub Desktop.
Save andreyfedoseev/25099bf6474e2d45f0ed to your computer and use it in GitHub Desktop.
Test the complexity of Python bisect module
S = """
bisect.bisect_left(range({N}), {x})
"""
if __name__ == '__main__':
import timeit
from matplotlib import pyplot
Ns = []
Ts = []
for log_N in range(3, 20):
N = 2 ** log_N
Ns.append(N)
Ts.append(timeit.timeit(S.format(N=N, x=0), setup="import bisect", number=100))
pyplot.plot(Ns, Ts)
pyplot.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment