# profiling

URL: /patitas/api/profiling/
Section: api
Description: Patitas ParseAccumulator — opt-in profiling for Markdown parsing.

This module provides accumulated metrics during parsing:
- Total parse time
- Source length
- Node count in resulting AST

Zero overhead when disabled (get_parse_accumulator() returns None).

Example:
    from patitas import parse
    from patitas.profiling import profiled_parse

    # Normal parse (no overhead)
    doc = parse("# Hello")

    # Profiled parse (opt-in)
    with profiled_parse() as metrics:
        doc = parse("# Hello **World**")

    print(metrics.summary())
    # {"total_ms": 1.2, "source_length": 18, "node_count": 4}

---

> For a complete page index, fetch /patitas/llms.txt.

Open LLM text
(/patitas/api/profiling/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fprofiling%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fprofiling%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fprofiling%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fprofiling%2Findex.txt)

Module

#
`profiling`

Patitas ParseAccumulator — opt-in profiling for Markdown parsing.

This module provides accumulated metrics during parsing:

- Total parse time

- Source length

- Node count in resulting AST

Zero overhead when disabled (get_parse_accumulator() returns None).

Example:

```
from patitas import parse
from patitas.profiling import profiled_parse

# Normal parse (no overhead)
doc = parse("# Hello")

# Profiled parse (opt-in)
with profiled_parse() as metrics:
    doc = parse("# Hello **World**")

print(metrics.summary())
# {"total_ms": 1.2, "source_length": 18, "node_count": 4}
```

1Class2Functions

## Classes

`ParseAccumulator`

7

▼

Accumulated metrics during Markdown parsing.

Opt-in profiling for debugging slow parsing.
Zero ove…

Accumulated metrics during Markdown parsing.

Opt-in profiling for debugging slow parsing.
Zero overhead when disabled (get_parse_accumulator() returns None).

#### Attributes

Name
Type
Description

`start_time`

`float`

Parse start timestamp.

`source_length`

`int`

Length of source being parsed.

`node_count`

`int`

Number of AST nodes produced.

`parse_calls`

`int`

Number of parse() calls recorded.

#### Methods

`total_duration_ms`

0

`float`

▼

Total profiling duration in milliseconds.

property

`def total_duration_ms(self) -> float`

##### Returns

`float`

`record_parse`

2

▼

Record a parse call.

`def record_parse(self, source_length: int, node_count: int) -> None`

##### Parameters

Name
Type
Description

`source_length`
`—`

Length of the source string parsed.

`node_count`
`—`

Number of AST nodes in the result.

`summary`

0

`dict[str, Any]`

▼

Get summary of parse metrics.

`def summary(self) -> dict[str, Any]`

##### Returns

`dict[str, Any]`

Dict with total_ms, source_length, node_count, parse_calls.

## Functions

`get_parse_accumulator`

0

`ParseAccumulator (/patitas/api/profiling/#ParseAccumulator) | None`

▼

Get current accumulator (None if profiling disabled).

`def get_parse_accumulator() -> ParseAccumulator | None`

##### Returns

`ParseAccumulator (/patitas/api/profiling/#ParseAccumulator) | None`

`profiled_parse`

0

`Iterator[ParseAccumulato…`

▼

Context manager for profiled parsing.

Creates a ParseAccumulator and makes it …

`def profiled_parse() -> Iterator[ParseAccumulator]`

Context manager for profiled parsing.

Creates a ParseAccumulator and makes it available via
get_parse_accumulator() for the duration of the with block.

##### Returns

`Iterator[ParseAccumulator (/patitas/api/profiling/#ParseAccumulator)]`
