Skip to content

Instantly share code, notes, and snippets.

@infinite-Joy
Created June 14, 2017 09:37
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 infinite-Joy/1dcdac1f1741757df21380cc8494aff3 to your computer and use it in GitHub Desktop.
Save infinite-Joy/1dcdac1f1741757df21380cc8494aff3 to your computer and use it in GitHub Desktop.
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