mobench-sdk-0.1.2 has been yanked.
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
- 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
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-sdk.toml- Configuration file
2. Add Benchmarks
use benchmark;
3. Build for Mobile
4. Run on Devices
Local emulator:
BrowserStack:
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 IPA │
└──────┬──────┘ └──────┬──────┘
│ │
└───────┬───────┘
↓
┌──────────────────────┐
│ Real Mobile Devices │
│ (BrowserStack/Local) │
└──────────────────────┘
Configuration
bench-sdk.toml
[]
= "my-benchmarks"
= "both" # android, ios, or both
[]
= "release" # or "debug"
[]
= "${BROWSERSTACK_USERNAME}"
= "${BROWSERSTACK_ACCESS_KEY}"
= "my-project-benchmarks"
[[]]
= "Pixel 7"
= "android"
= "13.0"
[[]]
= "iPhone 14"
= "ios"
= "16"
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)
- mobench-macros - Proc macros
- mobench-runner - Timing harness
See Also
- CLI Documentation for command-line usage
- UniFFI Documentation for FFI details
- BrowserStack App Automate for device testing
License
Licensed under either of:
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
at your option.