mobench-sdk
Mobile benchmarking SDK for Rust - run benchmarks on real Android and iOS devices.
Transform your Rust project into a mobile benchmarking suite. This SDK provides everything you need to benchmark your Rust code on real mobile devices via BrowserStack or local emulators/simulators.
Features
#[benchmark]macro: Mark functions for mobile benchmarking- Automatic registry: Compile-time function discovery
- Built-in timing harness: Lightweight timing infrastructure with warmup and iteration support
- Mobile app generation: Create Android/iOS apps from templates
- Build automation: Cross-compile and package for mobile platforms
- Statistical analysis: Mean, median, stddev, percentiles
- BrowserStack integration: Test on real devices in the cloud
- UniFFI bindings: Automatic FFI generation for mobile platforms
- Configuration file support:
mobench.tomlfor project settings
Quick Start
Add mobench-sdk to your project:
[]
= "0.1"
Mark functions to benchmark:
use benchmark;
Run programmatically:
use ;
Project Setup
1. Initialize Mobile Benchmarking
Use the mobench CLI to scaffold your project:
This creates:
bench-mobile/- FFI wrapper crateandroid/orios/- Mobile app projectsbench-config.toml- Configuration file
2. Add Benchmarks
use benchmark;
3. Build for Mobile
# Build to default output directory (target/mobench/)
# Or with verbose output
# Or preview what would be built
4. Run on Devices
Local device workflow (builds artifacts and writes the run spec; launch the app manually):
BrowserStack:
# Use --release for BrowserStack (smaller APK: ~133MB vs ~544MB debug)
Examples (Repository)
examples/basic-benchmark: minimal SDK usage with#[benchmark]examples/ffi-benchmark: full UniFFI surface withrun_benchmarkand FFI typescrates/sample-fns: repository demo library used by Android/iOS test apps
API Documentation
Core Functions
run_benchmark
Run a registered benchmark by name:
use ;
let spec = new?;
let report = run_benchmark?;
BenchmarkBuilder
Fluent API for building and running benchmarks:
use BenchmarkBuilder;
let report = new
.iterations
.warmup
.run?;
Types
BenchSpec
Benchmark specification:
RunnerReport
Benchmark results with statistical analysis:
Build API
Generate Mobile Projects
use ;
let config = InitConfig ;
let project_path = generate_project?;
Build for Android
use AndroidBuilder;
let builder = new?;
let apk = builder.build_apk?;
println!;
Build for iOS
use IosBuilder;
let builder = new?;
let xcframework = builder.build_xcframework?;
println!;
Examples
Crypto Benchmarks
use benchmark;
use ;
use Aes256;
JSON Parsing Benchmarks
use benchmark;
use ;
const JSON_DATA: &str = r#"{"name":"Alice","email":"alice@example.com","age":30}"#;
Data Structure Benchmarks
use benchmark;
use ;
Architecture
Workflow
- Development: Write benchmarks with
#[benchmark] - Compilation: Benchmarks registered at compile time via
inventory - FFI Generation: UniFFI creates type-safe Kotlin/Swift bindings
- Mobile Build: Cross-compile to mobile platforms
- Execution: Run on real devices or emulators
- Analysis: Collect and analyze timing data
Components
┌─────────────────────────────────────────┐
│ Your Rust Code + #[benchmark] │
└──────────────┬──────────────────────────┘
│
↓
┌─────────────────────────────────────────┐
│ mobench-sdk (Registry + Build Tools) │
└──────────────┬──────────────────────────┘
│
↓
┌─────────────────────────────────────────┐
│ UniFFI (FFI Bindings Generation) │
└──────────────┬──────────────────────────┘
│
┌───────┴───────┐
↓ ↓
┌─────────────┐ ┌───────────────────────┐
│ Android APK │ │ iOS xcframework / IPA │
└──────┬──────┘ └──────┬────────────────┘
│ │
└───────┬───────┘
↓
┌──────────────────────┐
│ Real Mobile Devices │
│ (BrowserStack/Local) │
└──────────────────────┘
Configuration
mobench.toml (Project Configuration)
mobench automatically loads mobench.toml from the current directory or parent directories:
[]
= "bench-mobile"
= "bench_mobile"
# output_dir = "target/mobench" # default
[]
= "com.example.bench"
= 24
= 34
[]
= "com.example.bench"
= "15.0"
[]
= "my_crate::my_benchmark"
= 100
= 10
bench-config.toml (Run Configuration)
= "android"
= "sample_fns::fibonacci"
= 100
= 10
= "device-matrix.yaml"
= ["default"] # optional; filter devices by tag
[]
= "${BROWSERSTACK_USERNAME}"
= "${BROWSERSTACK_ACCESS_KEY}"
= "my-project-benchmarks"
[]
= "target/mobench/ios/BenchRunner.ipa"
= "target/mobench/ios/BenchRunnerUITests.zip"
device-matrix.yaml
devices:
- name: "Google Pixel 7-13.0"
os: "android"
os_version: "13.0"
tags:
- name: "iPhone 14-16"
os: "ios"
os_version: "16"
tags:
Requirements
For Android
- Android NDK
cargo-ndk:cargo install cargo-ndk- Android SDK (API level 24+)
For iOS
- macOS with Xcode
- Rust targets:
aarch64-apple-ios,aarch64-apple-ios-sim xcodegen:brew install xcodegen
Part of mobench
This is the core SDK of the mobench ecosystem:
- mobench - CLI tool (recommended for most users)
- mobench-sdk - This crate (SDK library with timing harness, build automation, and codegen)
- mobench-macros -
#[benchmark]proc macro
See Also
- CLI Documentation for command-line usage
- UniFFI Documentation for FFI details
- BrowserStack App Automate for device testing
License
Licensed under the MIT License. See LICENSE.md for details.
Copyright (c) 2026 World Foundation