Last active
August 29, 2015 14:03
-
-
Save pkulev/e741f34fcec6c19f683e to your computer and use it in GitHub Desktop.
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
from datetime import datetime | |
DEBUG = True | |
TIMER = True | |
def logger(func): | |
import sys | |
def inner(*args, **kwargs): | |
sys.stdout.write("[{}] Calling FNAME with args: {} | kwargs: {}\n".format(datetime.now(), | |
args, | |
kwargs)) | |
res = func(*args, **kwargs) | |
sys.stdout.write("[{}] Result info: type::{}, value::{}\n".format(datetime.now(), | |
type(res), | |
res)) | |
return res | |
return inner if DEBUG else func | |
def timer(func): | |
from datetime import datetime | |
def inner(*args, **kwargs): | |
t1 = datetime.now() | |
res = func(*args, **kwargs) | |
t2 = datetime.now() | |
c = t2 - t1 | |
import sys | |
sys.stdout.write("[{}] Execution time: {}S : {}m\n".format(datetime.now(), | |
c.seconds, | |
c.microseconds)) | |
return res | |
return inner if TIMER else func | |
@timer | |
def dummy_func(n: int, reverse: bool = True) -> int: | |
a = 0 | |
for _ in range(n): | |
a += 1 | |
return int(str(a)[::-1]) if reverse else a | |
@logger | |
def foo(bar, baz=0, beer=True): | |
return "{} {} под окном {}\n".format(baz, bar, "хуй" if beer else "Лёша") | |
dummy_func(100000000) | |
print(foo("мох", baz=0.5)) | |
@logger | |
@timer | |
def fact(n): | |
if n <= 1: | |
return n | |
else: | |
return n * fact(n-1) | |
fact(150) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment