On this page
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
- Prefer
cProfile.run()for much lower measurement distortion.
REPL Inspect
from profile import run
help(run)
Linked from
Related notes
- tuts/python3/stdlib_module/profile/Profile Linked here; links to this page; shared tags: #profile, #stdlib
- tuts/python3/stdlib_module/profile/runctx Linked here; links to this page; shared tags: #profile, #stdlib
- tuts/python3/stdlib_module/profile links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib
- tuts/c/stdlib/ctype shared tags: #stdlib
- tuts/c/stdlib/ctype/isalpha shared tags: #stdlib
- tuts/c/stdlib/ctype/isdigit shared tags: #stdlib