mobench-sdk
Rust SDK for mobench mobile benchmarking. It provides the benchmark timing
harness, #[benchmark] registry integration, generated runner support, Android,
iOS, and WebAssembly builders, UniFFI compatibility, native/browser JSON
exports, and semantic profiling helpers used by the mobench CLI.
Current release: 0.2.0.
Features
#[benchmark]re-export frommobench-macros.- Inventory-backed benchmark discovery and runtime execution.
- Lightweight timing harness with warmup and measured iterations.
- Setup, teardown, and per-iteration benchmark inputs.
- Android and iOS build automation used by
cargo mobench build/run/ci run. - Browser-compatible timing and a worker-backed WebAssembly benchmark harness.
- Generated mobile runner templates for:
uniffi(default compatibility backend)native-c-abi(direct mobench JSON C ABI backend)
profile_phase(...)semantic phase annotations for native profile summaries.- Stable serializable timing/report types for mobile and CI integrations.
Install
Full SDK, including builders and code generation:
[]
= "0.2.0"
= "0.3"
Runtime-only benchmark crates that do not call SDK builders directly can use the narrower registry feature:
[]
= { = "0.2.0", = false, = ["registry"] }
= "0.3"
For generated mobile libraries, configure crate types:
[]
= ["cdylib", "staticlib", "lib"]
The cdylib crate type is also required for WebAssembly bundles.
Browser WebAssembly
WebBuilder compiles a registered benchmark crate for
wasm32-unknown-unknown, runs a caller-selected wasm-bindgen executable, and
emits a static worker-backed bundle:
use ;
let result = new
.wasm_bindgen
.build?;
println!;
# Ok::
The wasm-bindgen CLI version must match the Rust dependency selected by the
benchmark crate. Generated workers call the exported runBenchmarkJson
function off the main browser thread and return the normal RunnerReport JSON
contract.
Basic Benchmark
use benchmark;
Run the benchmark through the CLI:
Programmatic Runtime
use ;
Setup and Teardown
use benchmark;
Use per_iteration for mutable or consumed input:
use benchmark;
Generated Runner Backends
Generated mobile runners read backend configuration from mobench.toml:
[]
= "my-bench-crate"
= "my_bench_crate"
= "uniffi" # default; also supports "native-c-abi" and "boltffi"
[]
= "15.0"
# runner = "swiftui" # or "uikit-legacy" for legacy iOS targets
Use uniffi for the historical generated Kotlin/Swift binding path.
Use native-c-abi when you want generated Android and iOS runners to call
mobench's direct JSON C ABI and avoid UniFFI binding-generation overhead in the
measured path. Native C ABI benchmark crates should export the ABI from the
crate root:
export_native_c_abi!;
This exports:
mobench_run_benchmark_jsonmobench_free_bufmobench_last_error_messageMobenchBuf
Use boltffi when you want generated Android and iOS runners to call
BoltFFI-generated Kotlin/Swift bindings. Benchmark crates should export a
run_benchmark_json(spec_json: &str) -> Result<String, String> function with
#[boltffi::export].
iOS deployment targets below 15.0 select the UIKit legacy runner by default.
Forcing runner = "swiftui" below 15.0 fails early. Legacy BrowserStack
targets such as iPhone 7 on iOS 10 also require an older Xcode lane capable of
building for that OS.
Semantic Profiling Phases
Native profile runs can include semantic phase timings:
use ;
cargo mobench profile run merges these phases into the profile manifest and
summary while keeping native stack flamegraphs separate from semantic timing.
Build Through The CLI
The SDK builders are primarily driven by the CLI:
Build/run/list/verify/package commands resolve the benchmark crate and project
root from explicit flags, mobench.toml, Cargo workspace metadata, git root, or
the legacy bench-mobile/ layout.
Important Re-Exports
benchmarkdebug_benchmarksBenchmarkBuilderrun_benchmarkrun_benchmark_jsondiscover_benchmarksfind_benchmarklist_benchmark_namesBenchSpec,BenchSample,RunnerReport,BenchSummarySemanticPhase,HarnessTimelineSpan,TimingErrorprofile_phase,run_closureTarget,FfiBackend,BuildConfig,BuildProfile,BuildResultbuilders::{WebBuilder, WebBuildConfig, WebBuildResult}MobenchBuf
License
MIT licensed, World Foundation 2026.