Trying to write a decorator that displays the time of execution of the function. Please tell me that it is not so. Thank
Import Time
DEF TIME_OF_FUNCTION (FUNCTION):
Def Wrapped (FIRST, SECOND):
Start_Time = Time.Clock ()
FUNCTION (BIN (INT (STR (FIRST), 2) + INT (STR (SECOND), 2)))
Print (Time.Clock () - Start_Time)
Return Wrapped.
@time_of_function.
DEF TIME_OF_FUNC (FUNCTION):
Print (Function (111.0000))
Answer 1, Authority 100%
Apparently, you wanted to do so. Main error: The decorator does not need a function. Function logic – inside the function.
Import Time
DEF TIME_OF_FUNCTION (FUNCTION):
DEF Wrapped (* Args):
Start_Time = Time.perf_counter_ns ()
Res = Function (* Args)
Print (Time.perf_counter_ns () - Start_Time)
Return Res.
Return Wrapped.
@time_of_function.
DEF FUNC (FIRST, SECOND):
RETURN BIN (Int (FIRST, 2) + INT (SECOND, 2))
Print (FUNC ("111", "0000"))