mobench-macros
Procedural macros for the mobench mobile benchmarking toolkit.
This crate provides the #[benchmark] attribute macro. The macro preserves the
annotated Rust function, validates the benchmark signature at compile time, and
registers it through inventory so mobench-sdk and the cargo mobench CLI
can discover and run it.
Current release: 0.1.45.
Install
Most users should depend on mobench-sdk, which re-exports the macro:
[]
= "0.1.45"
= "0.3"
Direct macro use is also supported:
[]
= "0.1.45"
= { = "0.1.45", = false, = ["registry"] }
= "0.3"
Basic Example
use benchmark;
Setup, Teardown, and Per-Iteration Input
Setup code runs outside measured timing:
use benchmark;
Use per_iteration when the benchmark mutates or consumes its input:
use benchmark;
Teardown can clean up resources after measured iterations:
use benchmark;
Signature Rules
- Simple benchmarks take no parameters and return
(). - Setup benchmarks take one parameter matching the setup function output.
per_iterationsetup passes the setup value by value.- Non-
per_iterationsetup passes the setup value by reference. - Benchmark functions should be
pubwhen they need to be linked into generated mobile runners.
How It Works
#[benchmark] expands to registration code similar to:
submit!
The cargo mobench list, verify, run, and ci run commands use that
registry through the SDK runtime.
License
MIT licensed, World Foundation 2026.