A comprehensive resource documenting the time and space complexity of Python's built-in functions and standard library operations across different Python versions and implementations.
This project provides detailed documentation of algorithmic complexity for:
- Python Built-ins:
list,dict,set,str, etc. - Standard Library Modules:
collections,heapq,bisect,annotationlib,compression.zstd, and more - Python Versions: 3.9–3.14 (including new 3.14 features)
- Alternative Implementations: CPython, PyPy, Jython, IronPython
- 373 documented items with 118% coverage
- 4 Python implementations documented (CPython, PyPy, Jython, IronPython)
- 6 Python versions documented (3.9–3.14)
- 199 stdlib modules documented
- 📊 Comprehensive complexity tables for all major built-in types and operations
- 🔄 Version-specific behavior and optimization changes
- 🚀 Implementation-specific notes (CPython vs PyPy vs others)
- 🔍 Interactive search and filtering
- 📱 Mobile-friendly responsive design
Visit the documentation at: pythoncomplexity.com
- Python 3.9+ (3.14 recommended)
- uv - Fast Python package manager
- Git
# Install uv (one-time)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Clone and set up
git clone https://github.com/heikkitoivonen/python-time-space-complexity.git
cd python-time-space-complexity
# Install dependencies
uv sync
# Start development server
make serve
# Open http://localhost:8000make help # See all available commands
make dev # Install dev environment
make serve # Serve documentation locally
make build # Build static site
make check # Run lint + types + tests
make lint # Run linter
make format # Format code
make types # Run type checker
make test # Run tests
make clean # Clean build artifacts
make update # Update dependenciesuv sync # Sync dependencies
uv run mkdocs serve # Run command in venv
uv add package-name # Add dependency
uv add --dev pytest-plugin # Add dev dependency
uv lock --upgrade # Update dependencies├── docs/ # MkDocs documentation source
│ ├── index.md # Landing page
│ ├── builtins/ # Built-in types (list, dict, set, tuple, str)
│ ├── stdlib/ # Standard library modules
│ ├── implementations/ # CPython, PyPy, Jython, IronPython
│ └── versions/ # Python version guides (3.9–3.14)
├── data/ # JSON data files
│ └── documentation_audit.json
├── scripts/ # Utility scripts
│ └── audit_documentation.py
├── tests/ # Test files
├── .github/workflows/ # GitHub Actions CI/CD
│ └── deploy.yml
├── pyproject.toml # Project metadata and dependencies
├── mkdocs.yml # MkDocs configuration
└── Makefile # Development commands
git checkout -b feature/add-numpy-complexityvim docs/new-module.md
make serve # View at http://localhost:8000make lint # Check code quality
make format # Auto-format code
make types # Type checking
make test # Run tests
make check # All checks (required before commit)git add .
git commit -m "Add: NumPy array complexity documentation"
git push origin feature/add-numpy-complexity- Create markdown file in
docs/ - Add link to
mkdocs.ymlnavigation - Test locally with
make serve - Run
make checkbefore committing
- ruff for linting (line length: 100 chars, Python 3.9+ compatibility)
- pyright for static type checking
- pytest for testing
Type: Brief description
Types: Add, Fix, Update, Refactor, Docs, Test, Chore
Example: Add: List complexity documentation
| Operation | Time | Notes |
|---|---|---|
append() |
O(1)* | Amortized |
insert(i) |
O(n) | Shifts elements |
pop() |
O(1) | Last element |
pop(0) |
O(n) | First element |
in |
O(n) | Linear search |
sort() |
O(n log n) | Timsort/Powersort |
Pro tip: Use deque.appendleft() for O(1) prepend instead of list.insert(0).
| Operation | Time |
|---|---|
d[key] |
O(1) avg |
d[key] = v |
O(1) avg |
key in d |
O(1) avg |
set.add() |
O(1) avg |
x in set |
O(1) avg |
Pro tip: Use sets for fast membership testing, not lists.
| Operation | Time |
|---|---|
len() |
O(1) |
s[i] |
O(1) |
in (substring) |
O(n) avg |
split() / join() |
O(n) |
Pro tip: Use "".join(list) not += in loops.
| Module | Operation | Time |
|---|---|---|
| deque | append() / appendleft() |
O(1) |
| deque | pop() / popleft() |
O(1) |
| heapq | heapify() |
O(n) |
| heapq | heappush() / heappop() |
O(log n) |
| bisect | bisect_left/right() |
O(log n) |
# ❌ Bad: O(n) membership check
if item in list: pass
# ✅ Good: O(1) membership check
if item in set: pass
# ❌ Bad: O(n²) string concatenation
result = ""
for item in items:
result += item
# ✅ Good: O(n) string building
result = "".join(items)
# ❌ Bad: O(n) prepend
lst.insert(0, item)
# ✅ Good: O(1) prepend
from collections import deque
dq = deque()
dq.appendleft(item)Python 3.9 ← Baseline
Python 3.10 ← +5% improvements
Python 3.11 ← +10-60% improvements (inline caching!)
Python 3.12 ← +5-10% improvements
Python 3.13 ← Similar (experimental free-threading)
Python 3.14 ← Better GC pauses, new heapq max-heap
| Implementation | Use Case | Speed | GIL |
|---|---|---|---|
| CPython | Default, standard | Good | Yes |
| PyPy | CPU-bound loops | Excellent* | No |
| Jython | Java integration | Good | No |
| IronPython | .NET integration | Good | No |
- Push to GitHub
- Go to Settings → Pages
- Select Deploy from a branch → gh-pages
- GitHub Actions automatically deploys on push
- Update
site_urlinmkdocs.yml - Configure DNS to point to GitHub Pages
- In GitHub Settings → Pages, enter custom domain
- Enable HTTPS
make clean && make build
uv run mkdocs serve --verboserm -rf .venv/ && uv sync- Check GitHub Actions tab for errors
- Verify gh-pages branch exists
- Wait ~1-2 minutes for deployment
- Python Official Documentation
- TimeComplexity Wiki
- Python Enhancement Proposals (PEPs)
- uv Documentation
- MkDocs Documentation
- Material for MkDocs
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
MIT License - See LICENSE.txt for details
While we strive for accuracy, complexity information may vary based on specific implementations and versions. Always verify with official documentation and benchmarks for performance-critical code.