wisetimer 1.2.0
Smart timer with limits, code comparison and analysis
License: MIT
Requires Python: >=3.6
Keywords: timer, benchmark, performance

# ⏱️ WiseTimer - Smart Timer from 11-Year-Old Developer

![Python](https://img.shields.io/badge/python-3.6%2B-blue)
![License](https://img.shields.io/badge/license-MIT-green)
![Status](https://img.shields.io/badge/status-beta-orange)
![PyPI](https://img.shields.io/pypi/v/wisetimer)

Smart timer with limits, benchmarking, code comparison, and performance AI analysis.

## ✨ Features
✅All-in-one solution - multiple tools in one package  
✅For everyone - suitable for both beginners and advanced developers  
✅Multiple usage methods - methods, context managers, decorators, limits  
✅Beautiful output with emojis 😊    
✅Very simple API - easy to learn and use  
✅Clear error messages - human-readable with solutions  

## 📦 Installation
```bash
pip install wisetimer
```

## 🚀 Quick Start
```python

from wisetimer import Timer

from wisetimer import Analyze

from wisetimer import Benchmark

import time

timer = Timer()

a = Analyze()
    
# Basic timer

print(timer.start())

print("Hello wisetimer!") 

print(timer.stop())

# Context manager for benchmarking

with Timer() as t:

    x = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 

# Decorator for function timing

@Timer.funcTimer

def example():

    return "Hello world!"
    
result = example()

print(result)

# Benchmark comparison

with Benchmark("a"):

    print("Hello wisetimer!")

with Benchmark("b"):

    print("Hello wisetimer!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
    
Benchmark().compar()

Benchmark().reset()

with Benchmark("c"):

    print("Hello wisetimer")
    
with Benchmark("d"):

    print("Hello wisetimer!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
    
Benchmark().compar()

# Time limits

timer2 = Timer()

timer2.limit(0.1)# Set 0.1 second limit

for x in range(5):

    time.sleep(0.001)
    
    timer2.limitRevise()
    
print("✅Limit revise = OK")
    

# Code analysis
code = '''x = 0
for i in range(100):
    x = (range(1000))'''

analyzer = Analyze()

analyzer.AiCode(code)
```

## 📃 Detailed Documentation

### Timer Class

Timer is the base class containing all timer functions.

#### Import

```python

from wisetimer import Timer
```

#### Timer Methods

Timer().start() - starts the timer

Timer().stop() - stops the timer

Timer().lap()- creates a checkpoint without stopping

Timer().status() - returns timer status

Timer().reset() - stops and resets the timer

```python

timer = Timer()

print(timer.start())    # ✅Timer started!

x = 1234567890

print(timer.lap())      # 🚩Checkpoint at ... sec.

print(x \* 100)

print(timer.stop())     # ⏰Timer stopped...

print(timer.reset())    # ✅Timer reset!

print(timer.start())     # Start again

print("Hi!")

print(timer.status())   # ✔️Timer running...

print(timer.stop())      # ⏰Timer stopped...
```

Timer().limit(seconds) - sets execution time limit and starts counting

Timer().limitRevise() - checks if limit is exceeded

```python

timer = Timer()

timer.limit(0.1)

for x in range(5):

    time.sleep(0.001)
    
    timer.limitRevise()
```

@Timer.funcTimer - decorator for timing functions

```python

@Timer.funcTimer

def example():

    return "Hello!"
    
result = example()

print(result)  #🕒Function 'example' executed in ... sec.
```

Context Manager - simple benchmark with with statement

```python

with Timer() as t:

    x = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0
```

### Benchmark Class

Benchmark class for creating and comparing named benchmarks.

#### Benchmark Methods

Benchmark("name") - named benchmark (default name is "_")

Benchmark().compar() - compares benchmark execution times and ploting a graph

Benchmark().reset() - clears benchmark data

```python

with Benchmark("a"):

    print("Hello wisetimer!")
    
with Benchmark("b"):

    print("Hello wisetimer!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
    
Benchmark().compar() # Shows fastest and slowest

Benchmark().reset() # ✅Benchmarks reset!

with Benchmark("c"):

    print("Hello wisetimer")
    
with Benchmark("d"):

    print("Hello wisetimer!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
    
Benchmark().compar() # Shows fastest and slowest
```

### Analyze Class

Analyze class for code performance analysis and optimization advice.

#### Analyze Methods

Analyze().checkpoint("name") - sets checkpoints for speed analysis (minimum 4 checkpoints required)

Analyze().getAdvice() - provides performance patterns based on checkpoints

```python

for x in range(10):

    print(x)
    
    Analyze().checkpoint(x)
    
Analyze().getAdvice()
```

Analyze().AiCode('''Your code''') - analysis code using Google Gemeni AI!(the key is securely stored in the operating system(using the keyring library))

Analyze().AstCode('''Your code''') - analysis code using AST

```python

code = '''

for i in range(1000):

    result = []
    
    result.append(i \* 2)
    
'''

analyzer = Analyze()

analyzer.AiCode(code)
analyzer.AstCode(code)
```

## 😮Error explanation

All errors are understandable toa personand contain an explanationand solution to it

## ❓What's new?
🆕Improved documentation

🆕Simplified api

🆕Instead of ast analysis, Google Gamini 3 AI has been added(the key is securely stored in the operating system)

🆕Improved structure

🆕Added ASCII graphs

## 📊Comparison with analogues

| Feature | wisetimer |	time.time() | cProfile | timeit |
|---------|-----------|-------------|----------|--------|
| Ease of use | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐ | ⭐⭐ |
| Precision | nanoseconds | seconds | nanoseconds | nanoseconds |
| AI analysis | ✅ | ❌ | ❌ | ❌ |
| Optimization advice | ✅ | ❌ | ❌ | ❌ |
| Clear error messages | ✅ | ❌ | ❌ | ❌ |
| Time limits | ✅ | ❌ | ❌ | ❌ |


## 👦🏻About the Developer

My name is Andrey Egupov, I'm 11 years old. I've been programming for several years. Started with Scratch, now I write in Python and JavaScript.

The idea for this library didn't come out of nowhere. I wanted to create something truly useful, spent a long time asking AI assistants what libraries Python was missing. But I eventually found a suitable one. The wisetimer library not only measures time like regular timer libraries do, but also gives optimization advice. It's very simple and suitable for everyone - both beginners and advanced developers due to its simple interface and system accuracy.

During development I learned a lot - from what optimization advice to give for code performance improvement, to benchmarking and decorators.

In the future I plan to develop my library: I'll add more unique advice, progress bars, and much more.

## 📄License

This project is distributed under the MIT license. For more details see the LICENSE file.


\*Created by Andrey Egupov - 11-year-old developer 👦🏻

AI assistant helped with publication and development stages.

If you liked this project, please give it ⭐(a star) on GitHub\*