Created
February 10, 2019 15:21
-
-
Save kemingy/cd79cafd8ebe74cd18e8249c6edcf62e to your computer and use it in GitHub Desktop.
use decorator to count processing time
This file contains hidden or 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
| from time import time | |
| def timeit(func): | |
| def wrap(*args, **kwargs): | |
| start = time() | |
| result = func(*args, **kwargs) | |
| print('[Time]: {:6f}'.format(time() - start)) | |
| return result | |
| return wrap | |
| @timeit | |
| def multiply(n, nums=None): | |
| if nums: | |
| for i in nums: | |
| n *= i ** 2 | |
| return n | |
| if __name__ == '__main__': | |
| print(multiply(2, range(1, 10))) | |
| print(multiply(5, range(1, 10))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment