Skip to content

Instantly share code, notes, and snippets.

@cdgriffith
Created June 26, 2017 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdgriffith/a580db4f81d529f293f9a1821baf482e to your computer and use it in GitHub Desktop.
Save cdgriffith/a580db4f81d529f293f9a1821baf482e to your computer and use it in GitHub Desktop.
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