Created
April 11, 2021 09:48
-
-
Save ChaiBapchya/252f3ba9340006659b830bac06c961ef to your computer and use it in GitHub Desktop.
itertools vs for loop speed test
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 | |
print('------------For loop timeit-------------') | |
testcode=''' | |
a=[] | |
for i in range(1,1000): | |
a.append(i) | |
''' | |
print(timeit.timeit(stmt=testcode)) | |
print('------------itertool timeit-------------') | |
import_module = "import itertools as its" | |
testcode=''' | |
a=[] | |
for i in its.count(start=0,step=1): | |
if i<1000: | |
a.append(i) | |
else: | |
break | |
''' | |
print(timeit.timeit(stmt=testcode, setup=import_module)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment