Last active
September 13, 2021 16:33
-
-
Save VivienGiraud/4e5f58adc1318da304b26780cbb52873 to your computer and use it in GitHub Desktop.
Add timing decorator
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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
def flag(code): | |
OFFSET = ord('🇦') - ord('A') | |
return chr(ord(code[0]) + OFFSET) + chr(ord(code[1]) + OFFSET) | |
print(flag('FR')) | |
🇫🇷 | |
from functools import wraps | |
import time | |
def timing(f): | |
@wraps(f) | |
def wrap(*args, **kwargs): | |
time1 = time.time() | |
ret = f(*args, **kwargs) | |
time2 = time.time() | |
logger.info(f'{f.__name__:s} function took {(time2 - time1):.2f} s') | |
return ret | |
return wrap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment