Created
August 31, 2015 16:53
-
-
Save bradenmacdonald/0e03c7279a298e3d11d6 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 contextlib import contextmanager | |
from datetime import datetime | |
import time | |
def test_pass(): | |
print('.') | |
time.sleep(0.5) | |
return True | |
def test_FAIL(): | |
print('X') | |
time.sleep(0.5) | |
return False | |
@contextmanager | |
def time_code(desc): | |
t1 = datetime.now() | |
yield() | |
t2 = datetime.now() | |
print("{} took {} seconds".format(desc, (t2 - t1).seconds)) | |
with time_code("failure with conds second"): | |
valid = True | |
valid = valid and test_pass() | |
valid = valid and test_pass() | |
valid = valid and test_FAIL() | |
valid = valid and test_pass() | |
valid = valid and test_pass() | |
valid = valid and test_pass() | |
valid = valid and test_pass() | |
valid = valid and test_pass() | |
valid = valid and test_pass() | |
with time_code("pass with conds second"): | |
valid = True | |
valid = valid and test_pass() | |
valid = valid and test_pass() | |
valid = valid and test_pass() | |
valid = valid and test_pass() | |
valid = valid and test_pass() | |
valid = valid and test_pass() | |
valid = valid and test_pass() | |
valid = valid and test_pass() | |
valid = valid and test_pass() | |
with time_code("failure with conds first"): | |
valid = True | |
valid = test_pass() and valid | |
valid = test_pass() and valid | |
valid = test_FAIL() and valid | |
valid = test_pass() and valid | |
valid = test_pass() and valid | |
valid = test_pass() and valid | |
valid = test_pass() and valid | |
valid = test_pass() and valid | |
valid = test_pass() and valid | |
with time_code("pass with conds first"): | |
valid = True | |
valid = test_pass() and valid | |
valid = test_pass() and valid | |
valid = test_pass() and valid | |
valid = test_pass() and valid | |
valid = test_pass() and valid | |
valid = test_pass() and valid | |
valid = test_pass() and valid | |
valid = test_pass() and valid | |
valid = test_pass() and valid | |
# Result: | |
# failure with conds second took 1 seconds | |
# pass with conds second took 4 seconds | |
# failure with conds first took 4 seconds | |
# pass with conds first took 4 seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment