How to get the Execution Time of A Python Program

In order to get the execution time of a Python program, you can make use of the time() function from the time module.

time.time() returns the time in seconds since the epoch as a floating point number.

Documentaion: https://docs.python.org/3/library/time.html#time.time


Example:
import time

program_start_time = time.time()

def func1():
  print("func 1 called!")

def func2():
  print("func 2 called!")

def func3():
  print("func 3 called!")

func1()
func2()
func3()

program_end_time = time.time()

print("The Program took ", program_end_time - program_start_time," seconds to run!")
Result:
func 1 called!
func 2 called!
func 3 called!
The program took  0.0028166770935058594  seconds to run!
Get Execution Time of a Python Program

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!