A lightweight, thread-safe Python library for profiling both execution time and memory usage.
Project description
SmartProfiler
SmartProfiler is a lightweight and easy-to-use Python library designed to help you effortlessly profile both the execution time and memory usage of your Python code. Whether you're optimizing performance, debugging memory usage, or profiling applications running in multithreaded environments, SmartProfiler offers a clean and efficient solution.
Why SmartProfiler?
- Unified Profiling: Unlike other libraries that focus on either time or memory, SmartProfiler provides simple and intuitive decorators and context managers to profile both time and memory usage.
- Thread-Safe: Specifically designed to support multithreaded applications, ensuring that profiling works seamlessly across different threads without race conditions or conflicts.
- Minimal Overhead: The library is designed to introduce minimal performance overhead, so you can get accurate measurements without complicating your workflow.
- Easy to Use: With just a few lines of code, you can start profiling functions, blocks of code, or even specific lines with just decorators and context managers.
Features
- Function-Level Profiling: Profile execution time or memory usage using decorators.
- Code Block and Line Profiling: Profile specific blocks or lines of code using context managers.
- Multithreaded Profiling: Profile functions, blocks, and lines in multithreaded environments with thread safety.
- Flexible Logging: Integration with Python's logging framework for detailed insights into your code's performance.
Installation
You can easily install SmartProfiler via pip:
pip install smartprofiler
Usage Examples
Time Profiling for Functions
from smartprofiler import profile_time
@profile_time
def my_function():
time.sleep(1) # Simulate a time-consuming task
Memory Profiling for Functions
from smartprofiler import profile_memory
@profile_memory
def memory_intensive_function():
data = [1] * (10**7) # Simulate memory usage
Block Profiling (Time & Memory)
from smartprofiler import profile_block
with profile_block('time'):
time.sleep(1)
with profile_block('memory'):
data = [1] * (10**6)
Line Profiling (Time & Memory)
from smartprofiler import profile_line
with profile_line('time'):
result = sum([i for i in range(1000)])
with profile_line('memory'):
data = [1] * (10**6)
Multithreaded Profiling
import threading
from smartprofiler import profile_time
def thread_function():
with profile_time:
time.sleep(1)
threads = [threading.Thread(target=thread_function) for _ in range(5)]
for t in threads:
t.start()
for t in threads:
t.join()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 SmartProfiler-0.1.0.tar.gz.
File metadata
- Download URL: SmartProfiler-0.1.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0eabed6f75ef40e3342cb2ddb5781c76aee7a5e91021e5b91f5e62d58a9dd326
|
|
| MD5 |
30911a9e9c6543bc223e2c35443b588a
|
|
| BLAKE2b-256 |
1a8e30bfddd03735db7d27a290149af1bef56d887a3d94ea57b85dfab7700d1c
|
File details
Details for the file SmartProfiler-0.1.0-py3-none-any.whl.
File metadata
- Download URL: SmartProfiler-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5dc90ec40f1a63d130071f85fcedeb49893fd73757472124a74ed62b7de7730
|
|
| MD5 |
e83f7662e068f154ebe4f441114b219f
|
|
| BLAKE2b-256 |
900e291202459b9702ccf724f3ac9e05a391533a3fdb2d0d6c851c344c0bff5e
|