about-time

raw JSON →
4.2.2 verified Fri Apr 24 auth: no python

Easily measure timing and throughput of code blocks, with beautiful human friendly representations. It offers highly readable output for durations and counts, supporting various units from nanoseconds to days, and is particularly useful for profiling iterable operations like generators. The current version is 4.2.2, with active development indicated by frequent releases.

pip install about-time
error ModuleNotFoundError: No module named 'about_time'
cause The 'about-time' package is not installed in the Python environment.
fix
Install the package using pip: 'pip install about-time'.
error ImportError: cannot import name 'about_time'
cause Attempting to import 'about_time' directly instead of the correct function or class from the package.
fix
Use the correct import statement: 'from about_time import about_time'.
error AttributeError: module 'about_time' has no attribute 'about_time'
cause Incorrect import statement; 'about_time' is a function within the 'about_time' module, not an attribute.
fix
Import the function correctly: 'from about_time import about_time'.
error ModuleNotFoundError: No module named 'about-time'
cause The package name for installation uses a hyphen (`about-time`), but Python import statements require underscores (`about_time`).
fix
Change the import statement from import about-time to from about_time import about_time or import about_time.
error TypeError: 'int' object is not callable
cause When using `about_time` to measure a callable, a non-callable object (like an integer) was passed directly to it, expecting it to be executed.
fix
Ensure that the argument passed to about_time() in callable mode is indeed a callable object (e.g., a function, a lambda, or a method).
breaking Version 4.2.2 dropped support for Python 3.7. Ensure your environment is Python 3.8 or newer for compatibility.
fix Upgrade to Python 3.8+ or pin `about-time` to a version <4.2.2 if Python 3.7 is required.
breaking Version 4.0.0 introduced significant changes to the API and output, including new global features, new objects for each operation, and simpler human-friendly representations. Code written for pre-4.0 versions may require adaptation.
fix Refer to the official documentation for migration guidelines if upgrading from versions prior to 4.0.0.
gotcha Prior to version 4.2.2, the `precision` parameter for output formatting was not truly optional, potentially causing unexpected behavior. This was fixed in 4.2.2.
fix Upgrade to version 4.2.2 or higher to ensure the `precision` parameter behaves as expected.
runtime status import time mem disk
3.10-alpine 0.15s 3.7MB 17.8M
3.10-slim 0.12s 3.9MB 18M
3.11-alpine 0.24s 4.4MB 19.7M
3.11-slim 0.18s 4.4MB 20M
3.12-alpine 0.22s 5.0MB 11.6M
3.12-slim 0.20s 5.0MB 12M
3.13-alpine 0.16s 5.0MB 11.2M
3.13-slim 0.20s 5.0MB 12M
3.9-alpine 0.13s 3.6MB 17.3M
3.9-slim 0.12s 3.6MB 18M

Demonstrates basic usage with a context manager and advanced usage for profiling iterables/generators, showing human-readable output and direct attribute access.

import time
from about_time import about_time

# Example 1: Basic timing with a context manager
with about_time('Doing some work'):
    time.sleep(0.123)
    _ = [x * x for x in range(1000000)]

# Example 2: Timing an iterable (e.g., a generator)
def my_generator(n):
    for i in range(n):
        time.sleep(0.001)
        yield i

with about_time('Processing generator items') as t:
    total_sum = sum(my_generator(10))
    print(f'Total sum: {total_sum}')

# Accessing detailed results after the block
print(f"Duration: {t.duration_human}")
print(f"Throughput: {t.throughput_human}")