Created
June 14, 2017 09:37
-
-
Save infinite-Joy/1dcdac1f1741757df21380cc8494aff3 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
def timing_function(some_function): | |
""" | |
Outputs the time a function takes | |
to execute. | |
""" | |
def wrapper(*args, **kwargs): | |
t1 = time.time() | |
some_function(*args, **kwargs) | |
t2 = time.time() | |
print("Time it took to run the function: " + str((t2 - t1)) + "\n") | |
return wrapper | |
@timing_function | |
def transactions_filtered_by_querying_multiple_calls(calls): | |
for _ in range(calls): | |
mysql_engine = create_engine('mysql://{0}:{1}@{2}/{3}'.format(user, pwd, host, db)) | |
Session = sessionmaker(bind=mysql_engine) | |
session = Session() | |
transactions = ( | |
session.query(Transactions) | |
.filter( | |
cast(Transactions.created_at, Date) == '2007-09-02' | |
) | |
.all() | |
) | |
[(t.id, t.name, t.billing_type) for t in transactions] | |
@timing_function | |
def transactions_filtered_in_python_code_multiple_calls(calls): | |
mysql_engine = create_engine('mysql://{0}:{1}@{2}/{3}'.format(user, pwd, host, db)) | |
Session = sessionmaker(bind=mysql_engine) | |
session = Session() | |
transactions = session.query(Transactions).all() | |
for _ in range(calls): | |
[(t.id, t.name, t.billing_type) for t in transactions if t.created_at == '2015-05-11' ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment