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
Post a Comment
Write something to CodeWithAbdur!