CodeBeat is a line-by-line Python function tracer for debugging and performance analysis. It measures execution time per line across multiple runs, showing mean and standard deviation to identify bottlenecks
Project description
CodeBeat
CodeBeat is a line-by-line Python function tracer for debugging and performance analysis. It measures execution time per line across multiple runs, showing mean and standard deviation to identify bottlenecks in loops, branches, math operations, and list comprehensions.
Features
- Tracks individual line execution times with statistical summaries (mean/std in ms).
- Handles nested loops, conditionals, math functions, and dynamic list operations.
- Runs functions multiple times (e.g., 10-12 iterations) for reliable profiling.
- Displays formatted tables with line numbers, code, and timing metrics.
Where to get it
- The source code is currently hosted on GitHub at : https://github.com/SKR18156592/CodeBeat.
- Binary installers for the latest released version are available at the Python Package Index (PyPI).
Installation
You can install codebeat using pip:
pip install codebeat
Quick Start
Import the code_tracker module from the codebeat package, create an instance of it by passing the function you want to track as a parameter, and then utilize this instance to invoke the tracked function. When you create an instance using code_tracker(fun1), it generates a wrapper around fun1 that effectively measures and records the execution time line by line.
from codebeat import code_tracker
def fun1(x, y):
m = 0
for i in range(x):
for j in range(y):
m += i*j
return m
obj = code_tracker(fun1, 12) # Optional iteration count
result = obj(3, 4) # Executes 12x, prints timing table
Sample Output:
===========================================================================================
|> Function Name: fun1, #iter:12, mean_time(in ms):0.031, std_time(in ms):0.066
===========================================================================================
| line No | Line | mean_time(in ms) | std_time(in ms)
===========================================================================================
| 0 | m = 0 | 0.000 | 0.000
| 1 | for i in range(x): | 0.012 | 0.021
| 2 | for j in range(y): | 0.008 | 0.021
| 3 | m += i*j | 0.007 | 0.020
| 4 | return m | nan | nan
-------------------------------------------------------------------------------------------
Reveals nested loop overhead—outer loop takes ~50% more time than inner.
Examples
- Matrix Sum: Compares outer vs inner loop costs.
- Branch Counter: Highlights expensive
elsebranches. - Math Series: Trig/exp functions add measurable latency.
- List Builder:
append()dominates micro-benchmarks.
Project Structure
CodeBeat/
├── codebeat/
│ ├── __init__.py # Exports code_tracker
│ └── code_tracker.py # Main timing logic
├── example.ipynb # Usage demos
├── LICENSE
├── README.md
├── setup.py
└── requirements.txt
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codebeat-0.2.tar.gz.
File metadata
- Download URL: codebeat-0.2.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53941df7fe03d64a16ea7afa85fe41eb9bfb05eda92454a9a6d2fab8e0d824ba
|
|
| MD5 |
22baac20a7f22853517b9469eea3c895
|
|
| BLAKE2b-256 |
97cf0ca5327bdfdc08fb95a6b4a1b760b27976257efe022790c9791690c0fcf5
|
File details
Details for the file codebeat-0.2-py3-none-any.whl.
File metadata
- Download URL: codebeat-0.2-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2320ffd3df8f9e063efbcf2b658a2242bac6535940ddb5afac60cd5e7705f22f
|
|
| MD5 |
c392f54587c023c894b6b7d24693ee46
|
|
| BLAKE2b-256 |
17d17bcf63ba6f3a21d47e09833bc4f156d1ce2a810ac3348e3782aacad24752
|