Expand description
§mobench-macros
Procedural macros for the mobench mobile benchmarking SDK.
This crate provides the #[benchmark] attribute macro
that marks functions for mobile benchmarking. Functions annotated with this
macro are automatically registered in a global registry and can be discovered
and executed at runtime.
§Usage
Most users should import the macro via mobench-sdk
rather than using this crate directly:
ⓘ
use mobench_sdk::benchmark;
#[benchmark]
fn my_benchmark() {
// Your benchmark code here
let result = expensive_computation();
std::hint::black_box(result);
}§How It Works
The #[benchmark] macro:
- Preserves the original function - The function remains callable as normal
- Registers with inventory - Creates a static registration that the SDK discovers at runtime
- Captures the fully-qualified name - Uses
module_path!()to generate unique names likemy_crate::my_module::my_benchmark
§Requirements
- The
inventorycrate must be in your dependency tree - Functions must have no parameters and return
() - The function should not panic during normal execution
§Example: Multiple Benchmarks
ⓘ
use mobench_sdk::benchmark;
#[benchmark]
fn benchmark_sorting() {
let mut data: Vec<i32> = (0..1000).rev().collect();
data.sort();
std::hint::black_box(data);
}
#[benchmark]
fn benchmark_hashing() {
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
let mut hasher = DefaultHasher::new();
"hello world".hash(&mut hasher);
std::hint::black_box(hasher.finish());
}Both functions will be registered with names like:
my_crate::benchmark_sortingmy_crate::benchmark_hashing
§Crate Ecosystem
This crate is part of the mobench ecosystem:
mobench-sdk- Core SDK with timing harness (re-exports this macro)mobench- CLI toolmobench-macros(this crate) - Proc macros
Note: The mobench-runner crate has been consolidated into mobench-sdk as the timing module.
Attribute Macros§
- benchmark
- Marks a function as a benchmark for mobile execution.