Question:
Write a program to print the running time of execution of “1+1” for 100 times. Use timeit() function to measure the running time.
Program:
1 2 3 |
from timeit import Timer t = Timer("for i in range(100):1+1") print (t.timeit()) |
Explanation:
Runtime or execution time is the time during which a program is running (executing), in contrast to other program lifecycle phases such as compile time, link time and load time.
The Timer function keeps track of the time
Output:
1 |
1.8190948230039794 |
Leave a Reply