On this page
  1. profile.run
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

profile.run

Prev: profile.Profile | Up: profile | Next: profile.runctx
Rel: profile.Profile, profile.runctx
Ref: docs.python.org — profile.run
Tags: #public #python3 #stdlib #profile


Import

import profile
from profile import run

Signature & Overview

profile.run(statement, filename=None, sort=-1)

Run statement under profiler optionally saving results in filename This function takes a single argument that can be passed to the "exec" statement, and an optional file name. In all cases this

Usage

import contextlib, io, profile

buf = io.StringIO()
with contextlib.redirect_stdout(buf):
    profile.run("sum(range(100))")
assert "function calls" in buf.getvalue()

Gotchas

REPL Inspect

from profile import run
help(run)

Linked from

Related notes