Scalene: CPU, GPU, and Memory Profiler

2.2.1 · active · verified Wed Apr 15

Scalene is a high-resolution, low-overhead profiler for Python that analyzes CPU, GPU, and memory usage, providing AI-powered optimization suggestions. It's actively developed with frequent releases, typically addressing bug fixes, performance improvements, and compatibility updates for various Python versions and ecosystems.

Warnings

Install

Imports

Quickstart

Create a Python script (e.g., `my_script.py`) and then run Scalene from the command line using `python -m scalene my_script.py`. Scalene will generate a detailed profile in your terminal or an HTML report.

# my_script.py
import time
import math

def calculate_heavy_stuff(n):
    result = 0
    for _ in range(n):
        result += math.sin(math.sqrt(time.time()))
    return result

def main():
    print("Starting heavy calculations...")
    calculate_heavy_stuff(1000000) # Perform 1 million iterations
    print("Calculations finished.")

if __name__ == "__main__":
    main()

# To run the profiler from your terminal:
# python -m scalene my_script.py

view raw JSON →