Profiling

mew.memory.profile(entries, *, flamegraph=None, iterations=100)[source]

Profile each entry with memray over iterations measured loop passes.

Parameters:
  • entries (list[Entry]) – Benchmarks to profile.

  • flamegraph (Path | None) – If given, additionally writes a combined HTML flame graph to this path. Note this re-executes every case under a second tracker (memray capture files cannot be merged after the fact), roughly doubling profiling time.

  • iterations (int) – Measured timing-loop passes per case (a warmup runs first, untracked). Many passes amortize one-time allocations, keeping allocations_per_iteration comparable across engines.

Return type:

dict[str, MemoryProfile]

Returns:

dict[str, MemoryProfile] – Per-case profiles keyed by entry.name (or entry.name/case:<i> for each variant of a parametrized family).

class mew.memory.MemoryProfile(profiler, peak_bytes, total_bytes, total_allocations, iterations, allocations_per_iteration)[source]

Bases: object

Per-case memory summary captured by memray.

The capture is scoped to the timing loop (for _ in state), so fixture/setup allocations are excluded; iterations measured passes run after a warmup, making allocations_per_iteration a steady-state figure.

Variables:
  • peak_bytes (int) – Peak memory during the loop (metadata.peak_memory); a high-water mark, independent of iteration count.

  • total_bytes (int) – Tracked heap live at the high-water mark, not the cumulative sum.

  • total_allocations (int) – Cumulative allocation count across all iterations. Not comparable across runs of differing iteration count; use allocations_per_iteration.

  • iterations (int) – Number of measured timing-loop iterations the capture ran over.

  • allocations_per_iteration (float) – total_allocations / iterations, the per-call count, comparable across engines regardless of speed.

Parameters:
  • profiler (str)

  • peak_bytes (int)

  • total_bytes (int)

  • total_allocations (int)

  • iterations (int)

  • allocations_per_iteration (float)

mew.cpu.profile(entries, *, output=None, interval=0.0001, inner_iterations=1000)[source]

Profile each entry under pyinstrument.

Parameters:
  • entries (list[Entry]) – Benchmarks to profile.

  • output (Path | None) – If given, additionally writes a combined pyinstrument HTML report to this path.

  • interval (float) – Pyinstrument’s sampling period in seconds.

  • inner_iterations (int) – Times the benchmark body runs under the sampler per entry. Fast benchmarks need many iterations to accumulate samples.

Return type:

dict[str, CPUProfile]

Returns:

dict[str, CPUProfile] – Per-case profiles keyed by entry.name (or entry.name/case:<i> for each variant of a parametrized family).

Notes

state.pause() regions are excluded: the pause suspends the sampler, as pause() excludes setup from a timed run.

class mew.cpu.CPUProfile(profiler, wall_time, sample_count, top_function, top_function_total_self_time)[source]

Bases: object

Per-case CPU summary captured by pyinstrument.

Sampled out of the timing loop, so the figures are independent of the measured run; state.pause() regions are excluded.

Variables:
  • profiler (str) – Name of the sampling backend, always "pyinstrument".

  • wall_time (float) – Seconds the sampled execution took, including sampler overhead.

  • sample_count (int) – Stack samples collected. A low count means the body is too fast for the interval; raise inner_iterations.

  • top_function (str) – Hottest frame by self time, as function (file.py:lineno). "<no samples>" when nothing was captured.

  • top_function_total_self_time (float) – Seconds of self time attributed to top_function.

Parameters:
  • profiler (str)

  • wall_time (float)

  • sample_count (int)

  • top_function (str)

  • top_function_total_self_time (float)

profiler: str
wall_time: float
sample_count: int
top_function: str
top_function_total_self_time: float