A .NET library for turning C# methods into reproducible benchmarks, with automatic warm-up, statistics and result reports.
pyutils/line_profiler
Line-by-line profiler for Python that shows how much time each source line of a decorated function takes.
- Stars
- 3,252
- Forks
- 143
- Open issues
- 59
- Last commit
- 20 days ago
What is it?
line_profiler measures execution time line by line inside Python functions. It is useful once function-level profiling has pointed to a slow function and you need to see which specific lines account for the time. Functions are marked with the @profile decorator, and when the script finishes it prints a per-line summary of hits, time, and percentage of total time.
The recommended workflow is to import profile from line_profiler, decorate the functions of interest, and set the LINE_PROFILE=1 environment variable before running the script. The package also ships kernprof, a command-line helper, which supports the older kernprof -lv workflow. Installation is through pip, and the project requires Python 3.10 or newer.
This repository is the maintained fork that the PyPI line_profiler package now points to, continuing work on the original project by rkern. Documentation covers basic usage, examples, and an FAQ.
Key features
- 01Reports execution count, time, and percentage for each line of a decorated function.
- 02Enables profiling with the @profile decorator and the LINE_PROFILE environment variable.
- 03Includes the kernprof command-line helper.
- 04Installable from PyPI with pip, with wheels for common platforms.
- 05Optional IPython integration via the ipython extra.
Use cases
- Finding which lines inside a slow Python function consume most of the runtime.
- Profiling data processing or numerical scripts before optimizing them.
- Checking the effect of a code change on specific lines of a hot function.
Quick start
- 1
Install line_profiler with pip
pip install line_profiler - 2
Import profile and decorate the function you want to profile
- 3
Set LINE_PROFILE=1 and run your script as normal
Things to know
- Requires Python 3.10 or newer; older Python versions need older releases.
- Source installs may need a C compiler, and git checkouts also need Cython.
Topics
FAQ
- What is line_profiler?
- Line-by-line profiler for Python that shows how much time each source line of a decorated function takes. line_profiler measures execution time line by line inside Python functions. It is useful once function-level profiling has pointed to a slow function and you need to see which specific lines account for the time. Functions are marked with the @profile decorator, and when the script finishes it prints a per-line summary of hits, time, and percentage of total time.
- Is line_profiler free to use? What license does it have?
- line_profiler is open source under the Other license. Check the license terms before using it in commercial products.
- Is line_profiler still maintained?
- Actively maintained. The last commit to line_profiler was on Oct 18, 2026.
- What can I use line_profiler for?
- Finding which lines inside a slow Python function consume most of the runtime. Profiling data processing or numerical scripts before optimizing them. Checking the effect of a code change on specific lines of a hot function.
- How do I install line_profiler?
- Install line_profiler with pip: pip install line_profiler Import profile and decorate the function you want to profile Set LINE_PROFILE=1 and run your script as normal
- Where can I get line_profiler?
- The source code and installation instructions are on GitHub: https://github.com/pyutils/line_profiler
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A PHP development tool that shows request data, queries, logs, timelines and more in your browser, mainly for Laravel apps.
A single SKILL.md of .NET 10-11 performance tuning tips for AI coding agents, aimed mainly at benchmark workloads.
A memory profiler for Python that tracks allocations in Python code, native extensions, and the interpreter, with several report types.
A low-overhead Python tracer that records function calls and visualizes code execution as an interactive timeline.
A low-overhead, zero-instrumentation frame stack sampler for CPython, written in C, for profiling running Python processes.