Instantly share code, notes, and snippets.

Embed
What would you like to do?
import reusables
import os
# to be fair, start out at same state for both tests
os.makedirs("folder", exist_ok=True)
@reusables.time_it()
def test_lbyl(remove_folder=False):
for _ in range(10000):
if remove_folder:
os.rmdir("folder")
if not os.path.exists("folder"):
os.mkdir("folder")
@reusables.time_it()
def test_eafp(remove_folder=False):
for _ in range(10000):
if remove_folder:
os.rmdir("folder")
try:
os.mkdir("folder")
except FileExistsError:
pass
if __name__ == '__main__':
test_lbyl()
test_eafp()
print()
test_lbyl(remove_folder=True)
test_eafp(remove_folder=True)
# Function 'test_lbyl' took a total of 0.1620347726358246 seconds
# Function 'test_eafp' took a total of 0.10425737099405116 seconds
# Function 'test_lbyl' took a total of 5.379855266613499 seconds - kwargs: {'remove_folder': True}
# Function 'test_eafp' took a total of 3.9033870913335855 seconds - kwargs: {'remove_folder': True}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment