Skip to main content

a simple tool to monitor execution times of functions.

Project description

eprofiler

Execution & Memory Profiler for Python

A lightweight, zero-dependency toolset to monitor execution time and memory usage. eprofiler provides decorators and context managers to help you identify bottlenecks with minimal code.

PyPI version

Installation

pip install eprofiler

Features

  • @timeit: High-resolution execution timing.
  • @memit: Simple peak memory tracking.
  • @profile: Combined time and memory profiling in one shot.
  • Timer: A versatile class that works as both a context manager and a decorator.
  • Stats Capture: Pass a dictionary to handle results programmatically instead of printing.

Usage

1. Basic Timing (@timeit)

By default, decorators print a results dictionary to the console.

from eprofiler import timeit

@timeit(label="Computation")
def my_func():
    return sum(i**2 for i in range(100000))

my_func()

Output: {'label': 'Computation', 'function': 'my_func', 'duration': 0.008...}

2. Capturing Results in a Dictionary

If you pass a dictionary as the first argument, eprofiler populates it with the results instead of printing.

from eprofiler import timeit

results = {}

@timeit(results)
def process_data():
    # ... logic ...
    pass

process_data()
print(f"Time taken: {results['duration']} seconds")

3. Comprehensive Profiling (@profile)

Track both time and memory (current and peak) simultaneously.

from eprofiler import profile

@profile(label="Heavy Task")
def memory_intensive():
    return [x for x in range(1000000)]

memory_intensive()

Output: {'label': 'Heavy Task', 'function': 'memory_intensive', 'duration': 0.04, 'peak': 324502, 'current': 1204}

4. The Timer Class

The Timer class is perfect for timing specific blocks of code or being used as a persistent profiler.

from eprofiler import Timer

# Use as a context manager
with Timer("Database Query") as t:
    # ... code to time ...
    pass
print(t.stats)

# Use as a decorator
@Timer("Critical Path")
def critical_logic():
    pass

Links


Accuracy Note

When using @profile or @memit, Python's tracemalloc is enabled. This adds a slight "Tracer Tax" (overhead) to execution time. For the most precise timing-only results, use @timeit.

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

eprofiler-0.0.7.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

eprofiler-0.0.7-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file eprofiler-0.0.7.tar.gz.

File metadata

  • Download URL: eprofiler-0.0.7.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for eprofiler-0.0.7.tar.gz
Algorithm Hash digest
SHA256 6f2f9fe8f2200bec9fbb92294ea2fe084f00e12bf39f2eb8a828132217f2c880
MD5 67e79a19e7cc9f9ec0b508cc53de6bdc
BLAKE2b-256 4b8960b04cacb9710abd92edde640031942b63edbd3874759c95f7b54448d03e

See more details on using hashes here.

File details

Details for the file eprofiler-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: eprofiler-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for eprofiler-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 82077e9b0aaeaabb6cc7c2dbd7649938258d417f5244438793312cdfa2d34251
MD5 5b824b02da5f5b0d8db1ccc0757bac1f
BLAKE2b-256 eef242459531bcb25ab71d66fb8cc15e8245a606ebdb3a99ecc3853e60af5b42

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