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
def say_hello(): | |
print("hello") | |
>>> say_hello() | |
hello | |
>>> x=say_hello | |
>>> x() | |
hello |
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
def logging(f): | |
def wrapper(*args, **kwargs): | |
print("starting!") | |
retval = f(*args, **kwargs) | |
print("Done!") | |
return retval | |
return wrapper | |
say_hello = logging(say_hello) |
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
@logging | |
def say_hello(): | |
print("hello") | |
say_hello("bob") | |
=== Output ==== | |
starting! | |
hello bob! | |
Done! |
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 timeit import default_timer as timer | |
from datetime import timedelta | |
from functools import cache | |
def timefunc(f): | |
def wrapper(*a, **kw): | |
start = timer() | |
retval = f(*a, **kw) | |
end = timer() |
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
uncached | |
-------------------------------------------- | |
(40,) => 165580141 (0:00:22.154210 elasped) | |
(40,) => 165580141 (0:00:22.521894 elasped) | |
(40,) => 165580141 (0:00:22.835792 elasped) | |
-------------------------------------------- | |
(42,) => 433494437 (0:00:58.653067 elasped) | |
(42,) => 433494437 (0:01:00.355664 elasped) | |
(42,) => 433494437 (0:01:00.526576 elasped) | |
-------------------------------------------- |
OlderNewer