A Python Time and Space Complexity Analyzer
Project description
TimeSpaceX
A powerful Python Time and Space Complexity Analyzer that helps you understand the computational complexity of your code.
Features
- Analyzes both time and space complexity
- Provides detailed explanations
- Detects common patterns:
- Simple loops (O(n))
- Nested loops (O(n²), O(n³))
- Binary search patterns (O(log n))
- Divide and conquer algorithms (O(n log n))
- Recursive functions
- Matrix operations
- Beautiful command-line interface with syntax highlighting
Installation
pip install timespacex
Usage
Analyze a Python file:
timespacex your_file.py
Options:
timespacex --no-color your_file.py # Disable colored output
Example
Given a Python file example.py with the following content:
def binary_search(arr, target):
left, right = 0, len(arr) - 1
while left <= right:
mid = (left + right) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
left = mid + 1
else:
right = mid - 1
return -1
Running:
timespacex example.py
Will output:
Time & Space Complexity Analysis
==================================================
┌─ Function: binary_search ──────────────────────┐
│ The function `binary_search` has a time │
│ complexity of O(log n). This is because the │
│ function uses a binary search pattern, │
│ dividing the search space in half at each │
│ step. │
│ │
│ The space complexity is O(1). This is because │
│ the function uses a constant amount of extra │
│ space regardless of input size. │
└───────────────────────────────────────────────┘
Limitations
- The analysis is based on static code analysis and may not catch all edge cases
- Complex algorithmic patterns might not be accurately detected
- The tool provides simplified complexity analysis and may not catch subtle optimizations
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
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 timespacex-0.1.0.tar.gz.
File metadata
- Download URL: timespacex-0.1.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b04aa69b9d143e16603f8dacc1bd798e97711665505b6bb2e9c4945bb4a2eb19
|
|
| MD5 |
6a0b83208caf24f59bfecb184b158cfb
|
|
| BLAKE2b-256 |
66b3702b074d5ab916a30b69c80b80d96c40c326cf026031c4217138e91dd374
|
File details
Details for the file timespacex-0.1.0-py3-none-any.whl.
File metadata
- Download URL: timespacex-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7fe635221e353dc0c073e2cf17cee41fcaa6e503e9cbbbabaf97a5de55129ba
|
|
| MD5 |
3529e0b0246a4154cb19fafe6526b534
|
|
| BLAKE2b-256 |
d4a3f7b774ce86222af5928df3ee0111809686ed9cdc8bcc5d6755a7216277be
|