Created
September 8, 2022 02:28
-
-
Save rsp9u/63ac86e8c8b751ed3a703c1c78ef6a15 to your computer and use it in GitHub Desktop.
This file contains 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
from timeit import timeit | |
forloop = """ | |
arr = [] | |
for i in range(10000): | |
arr.append(i*i) | |
""" | |
listcomp = """ | |
arr = [i*i for i in range(10000)] | |
""" | |
fibdef = """ | |
def fib(x): | |
if (x == 1): | |
return 1 | |
else: | |
return x + fib(x - 1) | |
""" | |
# 3.10.6: 2.5244275940058287 | |
# 3.11.0rc: 1.639086764975218 | |
print(timeit(forloop, number=1000)) | |
# 3.10.6: 1.643876732996432 | |
# 3.11.0rc: 1.404964110988658 | |
print(timeit(listcomp, number=1000)) | |
# 3.10.6: 1.9977993569918908 | |
# 3.11.0rc: 1.0912171720119659 | |
print(timeit("fib(50)", setup=fibdef, number=100000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment