what are decorators in Python let's say
I'm building a python project and I
really want to time how long each of
these functions takes to run sure I
could go through each of these functions
and Implement some timing functionality
for each of them but what if I have
hundreds of functions that would take
forever instead I'm going to create a
function to do it for me let's call it
tick tock and it's going to take in a
function as an input now inside let's
create a function called wrapper now in
a wrapper let's define a start time and
then let's run the function that we
passed into Tick Tock and then after the
function is executed let's determine how
long it took by taking the current time
minus our start time now let's print
that it took T2 seconds to execute and
now down here let's return this wrapper
function so now all I have to do here is
do at sign Tick Tock over each of these
functions that I want to time python
sees this at symbol and understands that
this function under it needs to be
passed into a function called Tick Tock
then the function runs in Tick Tock with
these extra lines of code wrapped around
it so we can run this and there we go
you can see it timed each of these
functions and we can also add the
function name here in the print
statement so let's do 5 monk dot Dunder
name ran in T2 seconds so now when we
run it it gives us a bit more context be
sure to leave a like if you found this
helpful