PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from time import time #, sleep
def main():
# Decorate
@flexibleTimer
@ntimes(2)
def print(*args, **kwargs):
for i in range(1000000): j=i**5
__oldprint(*args, **kwargs)
# Execute a print
# print(*memoryview(b"Hello bling").tolist(), sep=":")
print("Hellooo decorators!")
######################################
# decorator functions
# I believe I adapted these from the video "What Does It Take To Be An Expert In Python?"
######################################
__oldprint = print
def flexibleTimer(funcToTime):
def workerfunc(*args, **kwargs):
before = time()
funcOutput = funcToTime(*args, **kwargs)
after = time()
__oldprint("*"*38, "Elapsed Time: {:.3} seconds".format(after - before), sep="\n")
return funcOutput
return workerfunc
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run