In this post we will be creating a script with a built in timer that will measure the time it takes to execute a function, to do this we will be using the time module which provides various time-related functions.
See the snippet of code below where we measure the time taken to print ‘Hello World!’
import time
start = time.time()
print("Hello World!")
end = time.time()
print(end - start)
In the case of the above we had received two outputs, one of which was the ‘Hello World!’ message and the other the time it had taken as seen below.
Hello World!
0.024884462356567383
>>>