-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c274f8
commit 847a46b
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import time | ||
from functools import partial | ||
|
||
|
||
def base_time_desc_decorator(method, desc='test_description'): | ||
def timed(*args, **kwargs): | ||
|
||
# Print Description | ||
# print('#' * 50) | ||
print(desc) | ||
# print('#' * 50 + '\n') | ||
|
||
# Calculation Runtime | ||
start = time.time() | ||
|
||
# Run Method | ||
try: | ||
result = method(*args, **kwargs) | ||
except TypeError: | ||
result = method(**kwargs) | ||
|
||
# Print Runtime | ||
print('Done! It took {:.2} secs\n'.format(time.time() - start)) | ||
|
||
if result is not None: | ||
return result | ||
|
||
return timed | ||
|
||
|
||
def time_desc_decorator(desc): return partial(base_time_desc_decorator, desc=desc) | ||
|
||
|
||
@time_desc_decorator('this is description') | ||
def time_test(arg, kwarg='this is kwarg'): | ||
time.sleep(3) | ||
print('Inside of time_test') | ||
print('printing arg: ', arg) | ||
print('printing kwarg: ', kwarg) | ||
|
||
|
||
@time_desc_decorator('this is second description') | ||
def no_arg_method(): | ||
print('this method has no argument') | ||
|
||
|
||
if __name__ == '__main__': | ||
time_test('hello', kwarg=3) | ||
time_test(3) | ||
no_arg_method() |