In python a so-called decorator is used to surround the code of the slow function python programer

preview_player
Показать описание
variation of the previous program that measures execution time of a piece of slow code. This time, a so-called decorator is used to surround the code of the slow function: the last line of the program does not mention "time_measure", but it will be still called by the compiler.

#time #measuretime #slowcode #fastcode #designpattern #decoratorpattern
#python #python3 #development #developer #programming #it #coding #program #programmer #programminglanguage #code #coding #pythonprogramming #pythoncode #software
#softwaredeveloper #geek #computers #learntocode #learnpython
Рекомендации по теме
Комментарии
Автор

cant wait to measure the time of the measure time function :)

JoeyTM
Автор

this is a very bad example! IN DECORATORS YOU ARE SUPPOSED TO RETURN A FUNCTION

ac
Автор

Decorators are used to add a functionality to a certain function which will be called before the function most of the time

animenosekai_edit
Автор

U do notice that even if you are sleeping for 2 seconds, it's running in fraction of a second xD

Decorators should always input a function and return another function which is supposed to be executed instead, what u are doing is returning a float which can't be call that's y calling slow_code is giving u exception

AdamSaudagar
Автор

I recommend using the standard python 'profile' (python 3) and 'cprofile' decorators. They use date time, so measurements are close to exact, it will also show you the number of sub-function calls for you to all figure out how to fix your code.

ayyythatguy
Автор

Why does this code make me want to puke?

hitorishinda
Автор

Perfect timing. I learn/ try to understand the decorator in a lession on ud*y at this time. Lol. It is scary!

(It is 00:21 am, 18th may, video 223)

hkn
Автор

Instead of adding a comment saying f = function, use ‘:’.
Eg.
def dosmth(a: int, b:str) -> int:

Where the ‘-> int’ signifies that the function will return an int

actorpus
Автор

Your videos are good, but this isn't the best implementation of decorator

uKaigo
Автор

So can you turn on/off decorators based on init argument in class initialization?

bartokon
Автор

Did you know that you can know your exact time with the following code?

import time
def my_time():
return

binayakumarsahu
Автор

Without args this is not really useful, not a good decorator

Kabelman
Автор

time.time() is deprecated
Use time.perfcounter() instead

destiny_
Автор

f is not a function, it's a parameter

lazar
Автор

I'm new to python please can someone explain to me what is f() 😅

eltalibmohamed
visit shbcf.ru