Performance Profiling

Measuring CPU performance metrics and memory bottlenecks in Python code blocks.

Lord1Egypt Updated 2 repo stars

File contents

Performance Profiling

Overview

Profiling calculates statistics of code execution, revealing bottleneck processes.

When to Use This Skill

Use to analyze slow mathematical scripts, inspect pillow memory footprint, or optimize algorithms.

Quick Start (with runnable code examples)

import cProfile

def count_primes():
    primes = []
    for num in range(2, 5000):
        if all(num % i != 0 for i in range(2, int(num**0.5) + 1)):
            primes.append(num)
    return len(primes)

# Run profile statistics output
cProfile.run('count_primes()')

Advanced Usage

Use line_profiler to trace memory and speed per script line, investigate memory leaks via tracemalloc, and generate flamegraphs.

Key References

Dependencies

  • Python Standard Library

Lord1Egypt/ai-skillforge/tree/main/js/skills/gemini/performance-profiling commit 0b60b6e18f

Frequently asked questions

npx skillmds@latest add lord1egypt/performance-profiling-2