On this page
profile.runctx
Prev: profile.run | Up: profile
Rel: profile.Profile, profile.run
Ref: docs.python.org — profile.runctx
Tags: #public #python3 #stdlib #profile
Import
import profile
from profile import runctx
Signature & Overview
profile.runctx(statement, globals, locals, filename=None, sort=-1)
Run statement under profiler, supplying your own globals and locals, optionally saving results in filename.
Usage
import contextlib, io, profile
buf = io.StringIO()
with contextlib.redirect_stdout(buf):
profile.runctx("sum(range(n))", {}, {"n": 100})
assert "function calls" in buf.getvalue()
Gotchas
- Prefer
cProfile.runctx()in everyday profiling.
REPL Inspect
from profile import runctx
help(runctx)
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/run 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