Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/m-pektas/pysimpler
This package simplifies the measuring duration of python functions.
https://github.com/m-pektas/pysimpler
cache decorators python reporting software-engineering timer
Last synced: about 5 hours ago
JSON representation
This package simplifies the measuring duration of python functions.
- Host: GitHub
- URL: https://github.com/m-pektas/pysimpler
- Owner: m-pektas
- License: apache-2.0
- Created: 2023-08-19T14:29:25.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-06T09:40:37.000Z (3 months ago)
- Last Synced: 2024-12-09T01:18:44.661Z (about 1 month ago)
- Topics: cache, decorators, python, reporting, software-engineering, timer
- Language: Python
- Homepage:
- Size: 132 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pysimpler
![version](https://img.shields.io/badge/version-0.0.7-blue)
This package simplifies the fundamental software engineering practices such as bottleneck analysis, exception handling, logging etc.
## Installation
```
pip install pysimpler
```## Environment Variables
You have to set PYSIMPLER environment variable as 1 to activate pysimpler. If you want to deactivate it, you should set as 0.
```
#activate
export PYSIMPLER=1#deactivate
export PYSIMPLER=0
```## Report
You can add the following command at the end of your code for reporting.
```python
pysimpler.reporter.report()
```If you want to set specific values for reporting metrics, you can use following lines. Default values are TIME_UNITS.SECONDS and 5 digits.
```python
import pysimpler
pysimpler.reporter.set_time_unit(pysimpler.TIME_UNITS.MILLISECONDS)
pysimpler.reporter.set_digits(10)
```
## Features
### 1. Time Logger
This feature aims to log duration of the execution time of method. We use **timer** keyword for using this feature. It help you analysing your bottlenecks in function level.
**Example:**
```python
import pysimpler@pysimpler.timer.time()
def counter(count):
x = 1
for i in range(count):
y = x*iif __name__ == '__main__':
print("Process 1")
result = counter(10)
print("Process 3")pysimpler.reporter.report()
# output
# ------------------------------
# Process 1
# 2023-12-25T11:55:38.474173+0300 | INFO | File: app.py | Function : counter | Duration : 0.0005151670000032027 sec
# Process 3
```### 2. Cache Cleaner
```python
import pysimpler
import gc@pysimpler.cache.clear()
def memory(count):
mem = []
for i in range(count):
mem.append("data")if __name__ == '__main__':
# print(gc.get_count()) lines are only for printing of the memory state.
# You can remove it.print("Process 1")
print("Process 2")
print(gc.get_count())
result = memory(1000)
print(gc.get_count())
print("Process 4")# output
#------------------------------
# Process 1
# Process 2
# (351, 10, 1)
# (0, 0, 0)
# Process 4
``````python
import pysimpler
import gc@pysimpler.cache.clear(pysimpler.MLFrameworks.PYTORCH)
def memory_pytorch(device = "cuda"):
print("=> memory_pytorch")
var = torch.ones(1,3,1024,1024)
if torch.cuda.is_available():
var = var.to(device)if __name__ == '__main__':
print("Process 1")
print("Process 2")
result = memory_pytorch()
print("Process 4")# output
# ------------------------------
# Process 1
# Process 2
# => memory_pytorch
# Process 4
``````