Skip to main content

An intelligent time and space complexity analyzer for Python code.

Project description

BigOwl - Intelligent Time and Space Complexity Analyzer 🦉

BigOwl is a Python library designed to analyze the time and space complexity of Python code. It provides tools to help developers understand the efficiency of their algorithms and data structures and suggests potential optimizations.

Version Python License

Features

  • Time Complexity Analysis: Analyze loops and recursive functions to estimate time complexity (O(n), O(n²), O(log n), etc.)
  • Space Complexity Analysis: Track memory allocation and analyze data structures to estimate space complexity
  • Optimization Suggestions: Get practical advice on how to improve your code's efficiency
  • Code Parsing: Utilize Python's ast and tokenize modules for robust code analysis
  • Easy Integration: Simple API for integrating with existing Python projects

Installation

Option 1: Install from PyPI (Recommended)

pip install BigOwl

Option 2: Install from Source

git clone https://github.com/CrazAr374/BigOwl.git
cd BigOwl
pip install -e .

Requirements

  • Python 3.6+
  • asttokens
  • networkx

Usage

Usage

Basic Example

from bigowl import analyze

code_str = """
def example_function(n):
    for i in range(n):
        print(i)
"""
result = analyze(code_str)
print(result)

Output:

{
    'Time Complexity': 'O(n)',
    'Space Complexity': 'O(n)',
    'Suggestions': []
}

Advanced Example: Nested Loops

from bigowl import analyze

code_str = """
def find_pairs(arr):
    pairs = []
    for i in range(len(arr)):
        for j in range(i+1, len(arr)):
            pairs.append((arr[i], arr[j]))
    return pairs
"""

result = analyze(code_str)
print(result)

Output:

{
    'Time Complexity': 'O(n^2)',
    'Space Complexity': 'O(n)',
    'Suggestions': [
        'Nested loops detected – consider optimizing using hashing or sets.',
        'Using range(len(x)) - consider using enumerate() for cleaner and potentially more efficient code.'
    ]
}

Advanced Example: Recursive Functions

from bigowl import analyze

code_str = """
def fibonacci(n):
    if n <= 1:
        return n
    return fibonacci(n-1) + fibonacci(n-2)
"""

result = analyze(code_str)
print(result)

Output:

{
    'Time Complexity': 'O(2^n)',
    'Space Complexity': 'O(n)',
    'Suggestions': [
        'Consider using memoization for recursive functions to avoid redundant calculations.'
    ]
}

How It Works

BigOwl analyzes your Python code in several steps:

  1. AST Parsing: Converts your code into an Abstract Syntax Tree
  2. Pattern Recognition: Identifies loops, recursions, and data structures
  3. Complexity Analysis: Uses rule-based analysis to determine Big O complexity
  4. Optimization Suggestions: Identifies patterns that could be optimized

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bigowl-0.1.0.tar.gz (14.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

bigowl-0.1.0-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

bigowl-0.1.0-py2.py3-none-any.whl (19.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file bigowl-0.1.0.tar.gz.

File metadata

  • Download URL: bigowl-0.1.0.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for bigowl-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b37866092266503b61836aa01c68f6f9fdc84f03cca94326e44744242d53f818
MD5 a376d53332b7ea0f611a8f7962a93dc9
BLAKE2b-256 f5792c1b008c48e559a7fd9f5d3ff6dd6b6b9e3015a61e342e613168709bee4a

See more details on using hashes here.

File details

Details for the file bigowl-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: bigowl-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for bigowl-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f47898c18794c5d91859502c0c0f01c56660b9edd33d549c473db0e09c03903c
MD5 edd9eaa514cdb0c2a2c6d34a8f38847f
BLAKE2b-256 7a2a6434481b67fac6622cdeda0fac10bc55920a1cbaf6f21b5d366c5e9e0241

See more details on using hashes here.

File details

Details for the file bigowl-0.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: bigowl-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for bigowl-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2164b5f9f4eec3aa4770033ec869d4abcaf679c65d27c13ac4144da6dc1827df
MD5 0e0f8c2b8eafa9a1e6f34ed882c14ff7
BLAKE2b-256 b2761b7a84f765850151b4d09690486ed7c2e6c40d528c0d4f1d4e390ca01b6a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page