Skip to content

Instantly share code, notes, and snippets.

View deadPix3l's full-sized avatar
👻

Skyler Curtis deadPix3l

👻
View GitHub Profile
def say_hello():
print("hello")
>>> say_hello()
hello
>>> x=say_hello
>>> x()
hello
def logging(f):
def wrapper(*args, **kwargs):
print("starting!")
retval = f(*args, **kwargs)
print("Done!")
return retval
return wrapper
say_hello = logging(say_hello)
@logging
def say_hello():
print("hello")
say_hello("bob")
=== Output ====
starting!
hello bob!
Done!
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()
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)
--------------------------------------------