Stopwatch for code execution
Project description
stwatch
A lightweight Python stopwatch library for timing code execution with precision. Features include lap timing, function execution timing, and context manager support.
Installation
pip install stwatch
Usage
Simple Timing
from stwatch import Stopwatch
# Basic usage
sw = Stopwatch()
sw.start()
# ... your code here ...
elapsed = sw.stop()
print(f"Operation took {elapsed:.2f} seconds")
# Using context manager
sw = Stopwatch()
with sw:
# ... your code here ...
print(f"Current time: {sw.elapsed_time():.2f}")
Timing Functions
from stwatch import Stopwatch
def expensive_operation():
# ... some time-consuming code ...
pass
sw = Stopwatch()
time_taken, result = sw.time_function(expensive_operation)
print(f"Function took {time_taken:.2f} seconds")
Lap Timing
sw = Stopwatch(start=True) # Start immediately
# Record named laps
lap_time, total_time = sw.lap("database_query")
lap_time, total_time = sw.lap("data_processing")
# Get lap info
db_lap_time, db_total = sw.get_lap(name="database_query")
proc_lap_time, proc_total = sw.get_lap(name="data_processing")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
stwatch-0.1.0.tar.gz
(4.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stwatch-0.1.0.tar.gz.
File metadata
- Download URL: stwatch-0.1.0.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8a541afb15a8fcfc454edb088542aff7b463c0e93004d6dc62612f34a850975
|
|
| MD5 |
93eb0cd6e984e11445b89cee0c877860
|
|
| BLAKE2b-256 |
6eb68069c8f37feae3421d848a892cb8f14ef8bae544977142eaf73402d917a1
|
File details
Details for the file stwatch-0.1.0-py3-none-any.whl.
File metadata
- Download URL: stwatch-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1bdf2284ee10d6286faf7788039eda106f2a70799decfa5a3ae678f6da1a884c
|
|
| MD5 |
a912e4b996a2a5f6e498f75693a33d2a
|
|
| BLAKE2b-256 |
93d62d2bb9c43a3acf4b1aeb3410174eab39c6c15655b82802568536532749c2
|