Skip to main content

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

Installation

  1. Clone the repo: git clone https://github.com/SKR18156592/CodeBeat.git
  2. Install: pip install -r requirements.txt (assumes codebeat as package).
  3. Import: from codebeat import code_tracker

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 else branches.
  • Math Series: Trig/exp functions add measurable latency.
  • List Builder: append() dominates micro-benchmarks.

Project Structure

CodeBeat/
├── codebeat/
│   └── __init__.py     # code_tracker class
├── example.ipynb       # Demos above
├── README.md
└── requirements.txt

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codebeat-0.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codebeat-0.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file codebeat-0.1.tar.gz.

File metadata

  • Download URL: codebeat-0.1.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

Hashes for codebeat-0.1.tar.gz
Algorithm Hash digest
SHA256 bf8a3f26bc97864e0f9da44255b2a870beafbbc36071bddd3d2eecf7145c07c7
MD5 1ea67622e517aeca9fe2b72dcf0257d5
BLAKE2b-256 55ed4cbc4ccd0359c7108dfcf9923e0c99efa2be7a1bffa48fab1e2976f4bb4c

See more details on using hashes here.

File details

Details for the file codebeat-0.1-py3-none-any.whl.

File metadata

  • Download URL: codebeat-0.1-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

Hashes for codebeat-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 864bfd4dfe28b177bdd92b9e5167f5ae9d26e76ba910a2245953a57f694e9cbb
MD5 beaddf3699c2b55e25f9a1d9864fbf82
BLAKE2b-256 742d13882b556f1d356e0540aaa5e1872f4c16a748a7039b3ef8aaa0a06f6e0c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page