Skip to content

Commit 916bae6

Browse files
authored
Merge pull request #1 from adwantg/feature/git-commit-tracking
Git Tracking, Stability Detection and Badge Generation features push
2 parents e0844f5 + 5228e18 commit 916bae6

9 files changed

Lines changed: 908 additions & 7 deletions

File tree

.gitignore

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,49 @@
11
# Author: gadwant
2+
# bigocheck .gitignore
3+
4+
# Python
25
__pycache__/
3-
.pytest_cache/
4-
.venv/
56
*.pyc
67
*.pyo
78
*.pyd
8-
*.log
9+
.Python
10+
*.so
11+
12+
# Virtual environments
13+
.venv/
14+
venv/
15+
ENV/
16+
17+
# Testing
18+
.pytest_cache/
19+
.coverage
20+
htmlcov/
21+
.tox/
22+
23+
# Build artifacts
924
dist/
1025
build/
1126
*.egg-info/
27+
*.egg
28+
.eggs/
29+
30+
# IDE
31+
.idea/
32+
.vscode/
33+
*.swp
34+
*.swo
35+
*~
36+
37+
# OS files
1238
.DS_Store
39+
Thumbs.db
40+
41+
# Logs
42+
*.log
43+
44+
# Generated files
45+
example_report.html
46+
*.baseline.json
47+
48+
# Release script (contains local paths)
1349
release.sh

README.md

Lines changed: 126 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Empirical complexity regression checker: run a target function across input size
1919
| **🧮 Time Complexity** | Fits to 9 classes: O(1), O(log n), O(√n), O(n), O(n log n), O(n²), O(n³), O(2ⁿ), O(n!) |
2020
| **📐 Space Complexity** | Classifies memory usage to complexity classes |
2121
| **📏 Polynomial Fitting** | Detect O(n^k) for arbitrary k (e.g., O(n^2.34)) |
22+
| **🔀 Git Commit Tracking** | Track complexity across commits, binary search for regression |
23+
| **⚠️ Instability Detection** | Detect noisy/unreliable benchmark results |
24+
| **🏷️ Badge Generation** | SVG badges for READMEs (color-coded by complexity) |
2225
| **📊 Statistical Significance** | P-values to validate complexity classification |
2326
| **🔄 Regression Detection** | CLI: `bigocheck regression --baseline file.json` |
2427
| **📉 Best/Worst/Avg Cases** | Analyze with sorted, reversed, and random inputs |
@@ -622,6 +625,104 @@ print(result) # "O(n)"
622625

623626
---
624627

628+
### 2️⃣1️⃣ Git Commit Tracking
629+
630+
Track complexity changes across git commits.
631+
632+
```python
633+
from bigocheck import track_commits, find_regression_commit
634+
635+
# Track across specific commits
636+
result = track_commits(
637+
target="mymodule:myfunc",
638+
commits=["v1.0", "v1.5", "v2.0"],
639+
sizes=[100, 500, 1000],
640+
)
641+
642+
print(result.summary)
643+
# Tracked 3 commits:
644+
# abc1234: O(n) (Initial implementation...)
645+
# def5678: O(n) (Optimized loop...)
646+
# ghi9012: O(n^2) (Added feature X...)
647+
#
648+
# ❌ Regression detected at ghi9012:
649+
# O(n) → O(n^2)
650+
651+
# Binary search for exact regression commit
652+
bad_commit = find_regression_commit(
653+
target="mymodule:myfunc",
654+
good_commit="v1.0",
655+
bad_commit="v2.0",
656+
sizes=[100, 500, 1000],
657+
)
658+
print(f"First bad commit: {bad_commit}")
659+
```
660+
661+
---
662+
663+
### 2️⃣2️⃣ Instability Detection
664+
665+
Detect when benchmark results are unreliable.
666+
667+
```python
668+
from bigocheck import benchmark_function, compute_stability, format_stability
669+
670+
analysis = benchmark_function(my_func, sizes=[100, 500, 1000], trials=5)
671+
stability = compute_stability(analysis)
672+
673+
print(format_stability(stability))
674+
# Stability: ✓ Stable (90%)
675+
#
676+
# Warnings:
677+
# ⚠️ Some variance detected in 1 measurements
678+
679+
if stability.is_unstable:
680+
print("⚠️ Results may be unreliable!")
681+
for warning in stability.warnings:
682+
print(f" - {warning}")
683+
for rec in stability.recommendations:
684+
print(f"{rec}")
685+
```
686+
687+
---
688+
689+
### 2️⃣3️⃣ Badge Generation
690+
691+
Generate SVG badges for your README.
692+
693+
```python
694+
from bigocheck import benchmark_function, generate_badge, save_badge
695+
696+
analysis = benchmark_function(my_func, sizes=[100, 500, 1000])
697+
698+
# Generate and save SVG badge
699+
badge = generate_badge(analysis.best_label) # Color-coded by complexity
700+
save_badge(badge, "docs/complexity_badge.svg")
701+
```
702+
703+
**Color Coding:**
704+
| Complexity | Color |
705+
|------------|-------|
706+
| O(1) | 🟢 Green |
707+
| O(log n) | 🟢 Light Green |
708+
| O(n) | 🟡 Yellow |
709+
| O(n log n) | 🟠 Orange |
710+
| O(n²) | 🔴 Red |
711+
| O(n³+) | 🔴 Dark Red |
712+
713+
**Use in README:**
714+
```markdown
715+
![complexity](docs/complexity_badge.svg)
716+
```
717+
718+
**Or use shields.io URL:**
719+
```python
720+
from bigocheck import generate_badge_url
721+
722+
url = generate_badge_url("O(n log n)")
723+
# https://img.shields.io/badge/complexity-O%28n%20log%20n%29-fe7d37
724+
```
725+
625726
## 🖥️ CLI Reference
626727

627728
```bash
@@ -734,6 +835,23 @@ from bigocheck import (
734835
start_repl, # Start REPL
735836
quick_check, # One-liner check
736837

838+
# Git Tracking
839+
track_commits, # Track complexity across commits
840+
find_regression_commit, # Binary search for bad commit
841+
CommitResult,
842+
TrackingResult,
843+
844+
# Stability Detection
845+
compute_stability, # Detect unreliable results
846+
format_stability,
847+
StabilityResult,
848+
849+
# Badge Generation
850+
generate_badge, # SVG badge
851+
generate_dual_badge, # Time + space badge
852+
save_badge,
853+
generate_badge_url, # shields.io URL
854+
737855
# Data Classes
738856
Analysis,
739857
Measurement,
@@ -751,7 +869,7 @@ from bigocheck import (
751869
```
752870
bigocheck/
753871
├── src/bigocheck/
754-
│ ├── __init__.py # Package exports (25+ functions)
872+
│ ├── __init__.py # Package exports (40+ functions)
755873
│ ├── core.py # Benchmarking and fitting
756874
│ ├── cli.py # CLI (run, regression, repl)
757875
│ ├── assertions.py # @assert_complexity, verify_bounds
@@ -766,13 +884,16 @@ bigocheck/
766884
│ ├── amortized.py # Amortized complexity analysis
767885
│ ├── parallel.py # Parallel benchmarking
768886
│ ├── interactive.py # REPL mode
887+
│ ├── git_tracking.py # Git commit tracking
888+
│ ├── stability.py # Instability detection
889+
│ ├── badges.py # Badge generation
769890
│ ├── datagen.py # Data generators
770891
│ ├── plotting.py # Optional matplotlib plots
771892
│ ├── pytest_plugin.py # pytest integration
772893
│ └── pre_commit.py # Pre-commit hook template
773894
├── .github/workflows/ # CI/CD templates
774895
├── docs/ # Documentation assets
775-
├── tests/ # Test suite (77+ tests)
896+
├── tests/ # Test suite (78+ tests)
776897
├── pyproject.toml
777898
├── CITATION.cff
778899
└── LICENSE
@@ -799,6 +920,9 @@ pytest -v
799920
- Amortized analysis
800921
- Parallel benchmarking
801922
- HTML report generation
923+
- Git commit tracking
924+
- Instability detection
925+
- Badge generation
802926

803927
---
804928

docs/complexity_badge.svg

Lines changed: 21 additions & 0 deletions
Loading

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Author: gadwant
22
[project]
33
name = "bigocheck"
4-
version = "0.5.0"
4+
version = "0.6.0"
55
description = "Zero-dependency empirical Big-O complexity checker for Python with CLI, assertions, and pytest integration"
66
readme = "README.md"
77
requires-python = ">=3.9"

src/bigocheck/__init__.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,29 @@
105105
quick_check,
106106
)
107107

108+
# Git tracking
109+
from .git_tracking import (
110+
CommitResult,
111+
TrackingResult,
112+
track_commits,
113+
find_regression_commit,
114+
)
115+
116+
# Stability detection
117+
from .stability import (
118+
StabilityResult,
119+
compute_stability,
120+
format_stability,
121+
)
122+
123+
# Badge generation
124+
from .badges import (
125+
generate_badge,
126+
generate_dual_badge,
127+
save_badge,
128+
generate_badge_url,
129+
)
130+
108131
__all__ = [
109132
# Version
110133
"__version__",
@@ -171,6 +194,21 @@
171194
# Interactive
172195
"start_repl",
173196
"quick_check",
197+
# Git Tracking
198+
"CommitResult",
199+
"TrackingResult",
200+
"track_commits",
201+
"find_regression_commit",
202+
# Stability
203+
"StabilityResult",
204+
"compute_stability",
205+
"format_stability",
206+
# Badges
207+
"generate_badge",
208+
"generate_dual_badge",
209+
"save_badge",
210+
"generate_badge_url",
174211
]
175212

176-
__version__ = "0.5.0"
213+
__version__ = "0.6.0"
214+

0 commit comments

Comments
 (0)