Created
December 13, 2017 12:13
-
-
Save andrievsky/ae2ffc13d67e3bd46e50040a148d4d8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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