Finding out the execution time of programs in Python

 

# we want to find out the execution time of printing "Abdur Rehman" 10 times
# by for loop method and multiplication method

import time

timei = time.time()
for i in range(1, 11):
    print("Abdur Rehman")
print("The time taken by For loop method is", time.time() - timei, "secs")

time2 = time.time()
print("abdur rehman\n" * 10)
print("The time taken by * method is", time.time() - time2, "secs")

# Result : For loop takes more time than * method.



Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

What is the difference between iostream and iostream.h in cpp?

The Basic Structure of a Full-Stack Web App