Getting Started
This section will help you install the library and basic usage of the stopwatch class.
Step. 1: Install the library.
bashpoetry add python-stopwatch2poetry add python-stopwatch2bashpython3 -m pip install python-stopwatch2python3 -m pip install python-stopwatch2bashpy -3 -m pip install python-stopwatch2py -3 -m pip install python-stopwatch2Step. 2: Import the Stopwatch class.
pythonfrom stopwatch import Stopwatchfrom stopwatch import StopwatchStep. 3: Create a new Stopwatch object.
pythonsw = Stopwatch()sw = Stopwatch()Step. 4: Do what you want.
pythonfrom time import sleep sleep(2)from time import sleep sleep(2)Step. 5: Stop the stopwatch.
pythonsw.stop()sw.stop()Step. 6: Get the elapsed time.
pythonprint(f'Time elapsed: {sw.elapsed}') # Time elapsed: 2.0031827000002522 # or print(f'Time elapsed: {sw}') # Time elapsed: 2.00sprint(f'Time elapsed: {sw.elapsed}') # Time elapsed: 2.0031827000002522 # or print(f'Time elapsed: {sw}') # Time elapsed: 2.00sFull example
pythonfrom stopwatch import Stopwatch from time import sleep sw = Stopwatch() sleep(2) sw.stop() print(f'Time elapsed: {sw}') # Time elapsed: 2.00sfrom stopwatch import Stopwatch from time import sleep sw = Stopwatch() sleep(2) sw.stop() print(f'Time elapsed: {sw}') # Time elapsed: 2.00s