Home python decorator that displays the time of execution of the function

decorator that displays the time of execution of the function

Author

Date

Category

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"))

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions