Reporters

class mew.Reporter(*args, **kwargs)[source]

Bases: Protocol

Duck-typed reporter interface consumed by the C++ runner.

Implementations must provide report_context and report_runs; finalize is optional. All callbacks run on the main thread with the GIL held.

report_context(context)[source]

Called once before any runs with the C++ context dict. Returning False aborts the Google Benchmark run.

report_runs(runs)[source]

Called one or more times with completed Run objects.

class mew.RichReporter(*, console=None, show_memory=False, show_cpu=False, show_label=False, show_variant=False)[source]

Bases: object

Stream one row per benchmark to a terminal as runs complete.

The header prints before any results land, so optional-column flags are passed up front.

Parameters:
  • console (Console | None) – Console to print to. Defaults to a fresh one.

  • show_memory (bool) – Add Peak Mem / Total Alloc columns.

  • show_cpu (bool) – Add Samples / Hottest Frame columns.

  • show_label (bool) – Add a Label column (the parametrize case id). Pass for families, where the case is otherwise indistinguishable from the truncated name.

  • show_variant (bool) – Add a Variant column (the --variant name). Pass when rows from several variants stream into one table, so they stay distinguishable.

report_context(context)[source]
Return type:

bool

Parameters:

context (dict[str, Any])

report_runs(runs)[source]
Return type:

None

Parameters:

runs (list[Run])

finalize()[source]
Return type:

None

class mew.JSONReporter(*, output=None)[source]

Bases: object

Emit a single {"context": ..., "benchmarks": [...]} document, GB-style.

To a seekable sink (a file) it streams: writes context + empty array up front, then each report_runs() seeks over the closing ]} and re-writes it, so the file is valid JSON after every flush (survives Ctrl-C). A non-seekable sink (stdout, pipe) can’t be rewritten, so it buffers and writes once at finalize().

Parameters:

output (Path | TextIO | None) – Destination. A Path is opened and closed here; a stream is written directly; None writes to sys.stdout.

report_context(context)[source]
Return type:

bool

Parameters:

context (dict[str, Any])

report_runs(runs)[source]
Return type:

None

Parameters:

runs (list[Run])

finalize()[source]
Return type:

None

class mew.ParquetReporter(*, output, append=False)[source]

Bases: object

Write a Parquet file with one row per benchmark Run.

Static schema; user context goes in a JSON string column custom (query via json_extract in DuckDB).

Parameters:
  • output (Path) – Destination file, overwritten if it exists.

  • append (bool) – If the file exists, concatenate this run’s rows onto it (one more session) instead of overwriting. Per-row session_id columns keep the sessions distinct.

Raises:

RuntimeError – From finalize() when pyarrow is not installed.

report_context(context)[source]
Return type:

bool

Parameters:

context (dict[str, Any])

report_runs(runs)[source]
Return type:

None

Parameters:

runs (list[Run])

finalize()[source]
Return type:

None

class mew.Fanout(reporters)[source]

Bases: object

Broadcast reporter callbacks to a list of underlying reporters.

Used by mew.run() to multiplex when multiple reporters are passed. report_context returns all(...) of the children’s responses, so the strictest sub-reporter wins.

Parameters:

reporters (list[Reporter]) – Underlying reporters. Calls are dispatched in iteration order.

report_context(context)[source]
Return type:

bool

Parameters:

context (dict[str, Any])

report_runs(runs)[source]
Return type:

None

Parameters:

runs (list[Run])

finalize()[source]
Return type:

None