Skip to content

Instantly share code, notes, and snippets.

@kurtbrose
Created February 21, 2019 05:14
Show Gist options
  • Save kurtbrose/f34524c7ad4de888505b057702df4fbe to your computer and use it in GitHub Desktop.
Save kurtbrose/f34524c7ad4de888505b057702df4fbe to your computer and use it in GitHub Desktop.
maybe we should never use range(len(list))
>>> import timeit
>>> LIST = [None] * 10
>>> countrange = lambda: [1 for i in range(len(LIST))]
>>> countdirect = lambda: [1 for e in LIST]
>>> timeit.timeit(countrange, number=1000) * 1000
0.8033999999952357
>>> timeit.timeit(countdirect, number=1000) * 1000
0.5680000000012342
>>> LIST = [None] * 100
>>> timeit.timeit(countrange, number=1000) * 1000
3.9718999999962534
>>> timeit.timeit(countdirect, number=1000) * 1000
3.175099999992881
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment