liveBook · Manning

Criterion_main macro

As explained in Refactoring to Rust

The criterion_main macro generates the main function for running registered Criterion benchmark groups.

The criterion_main macro generates the main function that starts registered Criterion benchmark groups. It supplies the entry point when the built-in benchmarking harness is disabled. section 6.5

Connect the benchmark group

A basic benchmark declares the group and passes its name to criterion_main!: criterion_main!(python_vs_rust); criterion_group!(python_vs_rust, bench_fn);. The group collects benchmark functions that share configuration. section 6.5

Figure 6.2 Anatomy of our benchmark program
figure

Use the benchmark-program anatomy figure to locate the generated entry point alongside the group and benchmark function. section 6.5

How Refactoring to Rust covers it

How deep it goes
Explains the generated main function and group input, but does not detail macro-expansion internals.
Examples
Uses a python_vs_rust group containing a bench_fn function that measures u8 and u128 addition.
What it assumes
Assumes Criterion dependencies and a disabled built-in harness, while teaching how the custom entry point fits the benchmark structure.
What you can do after
Builds a runnable Criterion benchmark harness by passing registered group names to criterion_main!.
How it connects
Connects Criterion, benchmark harnesses, criterion_group, and benchmark functions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Refactoring to Rust. The section links point to the parts of the book it draws on.