import timeit
test_list = '''
def div_by_five(num):
return True if num % 5 == 0 else False
xyz = [i for i in range({}) if div_by_five(i)]
for x in xyz:
pass
'''
test_gen = '''
def div_by_five(num):
return True if num % 5 == 0 else False
xyz = (i for i in range({}) if div_by_five(i))
for x in xyz:
pass
'''
test_sizes = [pow(10, x) for x in range(7)]
iterations = 100
results = [
(
timeit.timeit(test_list.format(size), number=iterations),
timeit.timeit(test_gen.format(size), number=iterations)
)
for size in test_sizes
]
print(results, test_sizes)