mobench
Mobile benchmarking CLI for Rust - Run benchmarks on real Android and iOS devices.
The mobench CLI is the easiest way to benchmark your Rust code on mobile devices. It handles everything from project setup to building mobile apps to running tests on real devices via BrowserStack.
Installation
Or use as a Cargo subcommand:
Quick Start
1. Initialize Your Project
# Create mobile benchmarking setup for Android
# Or for iOS
# Or for both platforms
This creates:
bench-mobile/- FFI wrapper crate with UniFFI bindingsandroid/orios/- Platform-specific app projectsbench-sdk.toml- Configuration filebenches/example.rs- Example benchmarks (with--generate-examples)
2. Write Benchmarks
// benches/my_benchmarks.rs
use benchmark;
3. Build for Mobile
# Build Android APK
# Build iOS app
4. Run Benchmarks
Local emulator/simulator:
On real devices via BrowserStack:
Commands
init - Initialize Project
Create mobile benchmarking infrastructure:
Options:
--target <android|ios|both>- Target platform (default: android)--output <FILE>- Config file path (default: bench-sdk.toml)
Example:
build - Build Mobile Apps
Cross-compile and package for mobile platforms:
|
Options:
--target <android|ios>- Platform to build for (required)--profile <debug|release>- Build profile (default: debug)
Examples:
# Build Android APK in release mode
# Build iOS xcframework
Outputs:
- Android:
android/app/build/outputs/apk/debug/app-debug.apk - iOS:
target/ios/sample_fns.xcframework
run - Run Benchmarks
Execute benchmarks on devices:
Options:
--target <android|ios>- Platform (required)--function <NAME>- Benchmark function name (required)--iterations <N>- Number of iterations (default: 100)--warmup <N>- Warmup iterations (default: 10)--devices <LIST>- Comma-separated device list for BrowserStack--local-only- Skip BrowserStack, run locally only--output <FILE>- Save results to JSON file--fetch- Fetch BrowserStack results after completion
Examples:
# Run locally
# Run on BrowserStack devices
# Run on iOS with auto-fetch
package-ipa - Package iOS IPA
Create a signed IPA for BrowserStack:
Options:
--scheme <NAME>- Xcode scheme (default: BenchRunner)--method <adhoc|development>- Signing method (default: adhoc)
Example:
Output: target/ios/BenchRunner.ipa
plan - Generate Device Matrix
Create a template device matrix file:
Example:
Output: device-matrix.yaml
devices:
- name: Pixel 7
os: android
os_version: "13.0"
tags:
- name: iPhone 14
os: ios
os_version: "16"
tags:
fetch - Fetch Results
Download BrowserStack build artifacts:
|
Options:
--target <android|ios>- Platform (required)--build-id <ID>- BrowserStack build ID (required)--output-dir <DIR>- Download directory (default: target/browserstack)
Example:
Configuration
Config File Format (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"
= ["default"]
[[]]
= "iPhone 14"
= "ios"
= "16"
= ["default"]
Environment Variables
BrowserStack credentials can be provided via:
-
Environment variables (recommended):
-
.env.localfile:BROWSERSTACK_USERNAME=your_username BROWSERSTACK_ACCESS_KEY=your_access_key -
Config file with variable expansion:
[] = "${BROWSERSTACK_USERNAME}" = "${BROWSERSTACK_ACCESS_KEY}"
Requirements
For Android
- Android NDK - Set
ANDROID_NDK_HOMEenvironment variable - cargo-ndk - Install with
cargo install cargo-ndk - Android SDK - API level 24+ required
- Gradle - For building APKs (bundled with Android project)
For iOS
- macOS with Xcode installed
- Xcode Command Line Tools -
xcode-select --install - Rust iOS targets:
- XcodeGen - Install with
brew install xcodegen
For BrowserStack
- BrowserStack App Automate account - Sign up
- Credentials - Username and access key from account settings
Examples
Benchmark Crypto Operations
# Initialize
# Add benchmark
# Build
# Run on multiple devices
Compare iOS Performance
# Run same benchmark on different iOS versions
CI Integration
# .github/workflows/mobile-bench.yml
name: Mobile Benchmarks
on:
jobs:
benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install mobench
run: cargo install mobench
- name: Setup Android NDK
uses: nttld/setup-ndk@v1
with:
ndk-version: r25c
- name: Build
run: cargo mobench build --target android --profile release
- name: Run benchmarks
env:
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
run: |
cargo mobench run my_benchmark \
--target android \
--devices "Pixel 7-13" \
--iterations 50 \
--output results.json \
--fetch
- name: Upload results
uses: actions/upload-artifact@v3
with:
name: benchmark-results
path: results.json
Workflow
┌─────────────────────┐
│ 1. cargo mobench │
│ init │
└──────────┬──────────┘
│
↓
┌─────────────────────┐
│ 2. Write benchmarks │
│ with #[benchmark]│
└──────────┬──────────┘
│
↓
┌─────────────────────┐
│ 3. cargo mobench │
│ build │
└──────────┬──────────┘
│
↓
┌─────────────────────┐
│ 4. cargo mobench │
│ run │
└──────────┬──────────┘
│
┌────┴────┐
↓ ↓
┌──────────┐ ┌──────────────┐
│ Local │ │ BrowserStack │
│ Emulator │ │ Real Devices │
└──────────┘ └──────────────┘
Troubleshooting
Android NDK not found
Or install via Android Studio: Tools → SDK Manager → SDK Tools → NDK
iOS code signing issues
For BrowserStack testing, use ad-hoc signing:
BrowserStack authentication failed
Verify credentials:
Or check .env.local file exists and contains valid credentials.
Benchmark function not found
Ensure:
- Function has
#[benchmark]attribute - Function is compiled into the mobile binary
- Function name matches exactly (case-sensitive)
Part of mobench
This CLI is part of the mobench ecosystem:
- mobench - This crate (CLI tool)
- mobench-sdk - SDK library
- mobench-macros - Proc macros
- mobench-runner - Timing harness
See Also
- mobench-sdk Documentation for programmatic API
- BrowserStack App Automate for device cloud
- UniFFI Documentation for FFI details
License
Licensed under the MIT License. See LICENSE.md for details.
Copyright (c) 2026 World Foundation