Created
March 31, 2022 10:24
-
-
Save Behoston/453be8248fd905d9792587d7dec6e726 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 random | |
import time | |
def if1(value): | |
if value == 0: | |
return 0 | |
if value == 1: | |
return 1 | |
if value == 2: | |
return 2 | |
if value == 3: | |
return 3 | |
if value == 4: | |
return 4 | |
if value == 5: | |
return 5 | |
if value == 6: | |
return 6 | |
if value == 7: | |
return 7 | |
if value == 8: | |
return 8 | |
if value == 9: | |
return 9 | |
def if2(value): | |
if value == 0: | |
return 0 | |
elif value == 1: | |
return 1 | |
elif value == 2: | |
return 2 | |
elif value == 3: | |
return 3 | |
elif value == 4: | |
return 4 | |
elif value == 5: | |
return 5 | |
elif value == 6: | |
return 6 | |
elif value == 7: | |
return 7 | |
elif value == 8: | |
return 8 | |
else: | |
return 9 | |
input_data = [random.randint(0, 9) for _ in range(1_000_000)] | |
repeats = 100 | |
t0 = time.time() | |
for _ in range(repeats): | |
for i in input_data: | |
if1(i) | |
t1 = time.time() | |
for _ in range(repeats): | |
for i in input_data: | |
if2(i) | |
t2 = time.time() | |
print(t1 - t0) | |
print(t2 - t1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
17.590487480163574
17.83971619606018