Created
October 14, 2018 03:01
-
-
Save pratos/45dd1b484f40925c57a71b6185cb509a to your computer and use it in GitHub Desktop.
Decorator: TImeit
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 timeit(method): | |
def timing(*args, **kwargs): | |
timings = [] | |
print("Running this 1000 loops, for benchmarking") | |
for i in range(1000): | |
start = time.time() | |
result = method(*args, **kwargs) | |
end = time.time() | |
timings.append(end-start) | |
average = np.average(timings) | |
std_dev = statistics.stdev(timings) | |
print("{:.2f} ms ± {:.3f} ms average time taken per loop (mean ± std. dev. to run 1000 loops)"\ | |
.format(average*1000, std_dev*1000)) | |
return(result) | |
return(timing) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment