Skip to content

Instantly share code, notes, and snippets.

@andrievsky
Created December 13, 2017 12:13
Show Gist options
  • Save andrievsky/ae2ffc13d67e3bd46e50040a148d4d8e to your computer and use it in GitHub Desktop.
Save andrievsky/ae2ffc13d67e3bd46e50040a148d4d8e to your computer and use it in GitHub Desktop.
import timeit
COUNT = 1000
CITIES = []
for i in range(COUNT):
CITIES.append("city_" + str(i))
def testWithoutTuples(cities):
res = 0
for city in cities:
res += 1
return res
def testWithTuples(cities):
res = 0
for index, city in enumerate(cities):
res += 1
return res
print(timeit.timeit('testWithoutTuples(CITIES)', globals=globals())) # 45.13318726621658
print(timeit.timeit('testWithTuples(CITIES)', globals=globals())) # 71.42498460450689
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment