Python: Calculate the time runs of a program
Python Basic: Exercise-133 with Solution
Write a Python program to calculate the time runs (difference between start and current time)of a program.
from timeit import default_timer def timer(n): start = default_timer() # some code here for row in range(0,n): print(row) print(default_timer() - start) timer(5) timer(15)
0 1 2 3 4 2.6107000849151518e-05 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 4.1371999941475224e-05
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Python skills with w3resource's quiz
Python: Tips of the Day
>>> m = [x ** 2 for x in range(5)] >>> m [0, 1, 4, 9, 16]
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework