Expand description
Lightweight benchmarking harness for mobile platforms.
This module provides the core timing infrastructure for the mobench ecosystem.
It was previously a separate crate (mobench-runner) but has been consolidated
into mobench-sdk for a simpler dependency graph.
The module is designed to be minimal and portable, with no platform-specific dependencies, making it suitable for compilation to Android and iOS targets.
§Overview
The timing module executes benchmark functions with:
- Configurable warmup iterations
- Precise nanosecond-resolution timing
- Simple, serializable results
§Usage
Most users should use this via the higher-level crate::run_benchmark function
or crate::BenchmarkBuilder. Direct usage is for custom integrations:
use mobench_sdk::timing::{BenchSpec, run_closure, TimingError};
// Define a benchmark specification
let spec = BenchSpec::new("my_benchmark", 100, 10)?;
// Run the benchmark
let report = run_closure(spec, || {
// Your benchmark code
let sum: u64 = (0..1000).sum();
std::hint::black_box(sum);
Ok(())
})?;
// Analyze results
let mean_ns = report.samples.iter()
.map(|s| s.duration_ns)
.sum::<u64>() / report.samples.len() as u64;
println!("Mean: {} ns", mean_ns);§Types
| Type | Description |
|---|---|
BenchSpec | Benchmark configuration (name, iterations, warmup) |
BenchSample | Single timing measurement in nanoseconds |
BenchReport | Complete results with all samples |
TimingError | Error conditions during benchmarking |
§Feature Flags
This module is always available. When using mobench-sdk with default features,
you also get build automation and template generation. For minimal binary size
(e.g., on mobile targets), use the runner-only feature:
[dependencies]
mobench-sdk = { version = "0.1", default-features = false, features = ["runner-only"] }Structs§
- Bench
Report - Complete benchmark report with all timing samples.
- Bench
Sample - A single timing sample from a benchmark iteration.
- Bench
Spec - Benchmark specification defining what and how to benchmark.
Enums§
- Timing
Error - Errors that can occur during benchmark execution.
Functions§
- run_
closure - Runs a benchmark by executing a closure repeatedly.
- run_
closure_ with_ setup - Runs a benchmark with setup that executes once before all iterations.
- run_
closure_ with_ setup_ per_ iter - Runs a benchmark with per-iteration setup.
- run_
closure_ with_ setup_ teardown - Runs a benchmark with setup and teardown.