Skip to main content

Performance Profiler & Optimizer 🚀

A comprehensive Python toolkit for profiling and optimizing code performance with intelligent auto-suggestions and historical tracking.

Python Version Version License

✨ Features

  • 💾 Memory Profiling - Track memory usage and allocations across your application
  • 🔍 Line-by-Line Analysis - Detailed performance insights for each line of code
  • 💡 Auto-Optimization Suggestions - AI-powered recommendations for code improvements
  • 📊 Before/After Comparisons - Visual performance improvement metrics
  • 🎯 Bottleneck Highlighting - Automatically identify and prioritize slow code
  • 📈 Historical Tracking - Monitor performance trends over time with SQLite database

📦 Installation

pip install performance-profiler-optimizer

Or install from source:

git clone https://github.com/yourusername/performance-profiler-optimizer.git
cd performance-profiler-optimizer
pip install -e .

🚀 Quick Start

Basic Performance Profiling

from performance_profiler import PerformanceProfiler

profiler = PerformanceProfiler()

@profiler.profile
def my_function():
    return sum(range(1000000))

my_function()
profiler.print_results()

Memory Profiling

from performance_profiler import MemoryProfiler

memory_profiler = MemoryProfiler()
memory_profiler.enable()

@memory_profiler.profile_memory
def memory_intensive_task():
    return [i**2 for i in range(1000000)]

memory_intensive_task()
memory_profiler.print_results()

Line-by-Line Analysis

from performance_profiler import LineByLineProfiler

line_profiler = LineByLineProfiler()

@line_profiler.profile_lines
def complex_function():
    data = [i for i in range(10000)]
    filtered = [x for x in data if x % 2 == 0]
    return sum(filtered)

complex_function()
line_profiler.print_results(top_n=15)

Auto-Optimization Suggestions

from performance_profiler import OptimizerEngine

optimizer = OptimizerEngine()

# Analyze code
code = """
def inefficient():
    result = []
    for i in range(1000):
        result.append(i * 2)
    return result
"""

suggestions = optimizer.analyze_code(code)
optimizer.print_suggestions(suggestions)

Before/After Comparisons

from performance_profiler import ComparisonEngine

comparator = ComparisonEngine()

def before_optimization(n):
    result = ""
    for i in range(n):
        result += str(i)
    return result

def after_optimization(n):
    return ''.join(str(i) for i in range(n))

result = comparator.compare_functions(
    before_func=before_optimization,
    after_func=after_optimization,
    args=(1000,),
    iterations=100
)
comparator.print_comparison(result)

Bottleneck Detection

from performance_profiler import BottleneckDetector

detector = BottleneckDetector()

@detector.detect_bottlenecks
def slow_function():
    result = 0
    for i in range(1000):
        for j in range(1000):
            result += i * j
    return result

slow_function()
detector.print_bottlenecks()

Historical Tracking

from performance_profiler import HistoricalTracker

tracker = HistoricalTracker(db_path="performance.db")

@tracker.track
def monitored_function():
    return sum(range(100000))

# Run multiple times to build history
for _ in range(10):
    monitored_function()

# View history and trends
tracker.print_history("monitored_function", limit=10)
trend = tracker.get_trend("monitored_function", "execution_time")
print(f"Performance trend: {trend['trend']}")

📖 Documentation

Module Overview

PerformanceProfiler

Basic execution time profiling with call statistics.

MemoryProfiler

Track memory allocations, peak usage, and memory changes.

LineByLineProfiler

Detailed line-by-line execution analysis with hotspot detection.

OptimizerEngine

Pattern-based and AST code analysis for optimization suggestions.

ComparisonEngine

Compare before/after optimization metrics with improvement calculations.

BottleneckDetector

Detect and classify performance bottlenecks by severity (critical, high, medium).

HistoricalTracker

SQLite-backed performance tracking with trend analysis and reporting.

📊 Examples

Check the examples/ directory for comprehensive demonstrations:

  • basic_usage.py - Simple profiling example
  • memory_profiling.py - Memory tracking demo
  • line_profiling.py - Line-by-line analysis
  • optimization_suggestions.py - Auto-optimization examples
  • before_after_comparison.py - Comparison demonstrations
  • bottleneck_detection.py - Bottleneck identification
  • historical_tracking.py - Historical data tracking

🔧 Requirements

  • Python 3.7+
  • psutil >= 5.8.0

📝 Development History

This project was developed incrementally with the following milestones:

  • Jan 2020: Initial project structure and core profiler
  • Apr 2020: Memory profiling capabilities
  • Jul 2020: Line-by-line analysis implementation
  • Oct 2020: Auto-optimization suggestion engine
  • Jan 2021: Before/after comparison system
  • Apr 2021: Bottleneck detection and highlighting
  • Jul 2021: Historical tracking with database (v1.0.0)

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Built with Python's built-in profiling capabilities
  • Uses psutil for system-level metrics
  • Inspired by various profiling tools in the Python ecosystem

📧 Contact

For questions, issues, or suggestions, please open an issue on GitHub.


Made with ❤️ by the Performance Optimizer Team

Metadata

Release files for performance-profiler-optimizer 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for performance-profiler-optimizer 1.0.0
File Size Uploaded Provenance
performance_profiler_optimizer-1.0.0.tar.gz 25.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for performance-profiler-optimizer 1.0.0
File Interpreter ABI Platform
performance_profiler_optimizer-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 47.0 kB

Release files / performance_profiler_optimizer-1.0.0.tar.gz

Download URL performance_profiler_optimizer-1.0.0.tar.gz
Size 25.4 kB
Tags Source
SHA-256 checksum
How to use checksums
430e1dfbb2fc838412a73b4c0cb5ce3ec498de6148ab526e072ec7f78d246a2d
BLAKE2b-256 checksum
How to use checksums
38b204676fa24fbb5b9b8faa52c5789c10cbe4978b2c2f8ee6d4f6a9a3e57083
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / performance_profiler_optimizer-1.0.0-py3-none-any.whl

Download URL performance_profiler_optimizer-1.0.0-py3-none-any.whl
Size 21.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
39dce5bdeab42f0e22ddf48cb4ff931b47d79127c0843eab55ffd1d439f29d71
BLAKE2b-256 checksum
How to use checksums
9c39e4056b7b208ddb627c26d443e222e32dc2e693e43c97d5fab65580c90f36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Security for performance-profiler-optimizer 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page