Inspired by MATLAB's tic/toc I've written a short helper function for calculating execution time.
from time import time
def tic():
"""Simple helper function for timing executions.
Returns a closure that holds current time when calling tic().
Usage:
toc = tic()
//some code
print(toc())
"""
t = time()
return (lambda: (time() - t))
I'm well aware that there are python modules (e.g. timeit) that handle this kind of problem. However I do not want to time the execution of a whole script. I'm using this function in an interavtive shell for querying a mssql server.
What do you think? Is this good practice?