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 projects (generated to output directory)bench-config.toml- Run configuration filemobench.toml- Project configuration file (when usinginit-sdk)benches/example.rs- Example benchmarks (with--examples)
2. Write Benchmarks
// benches/my_benchmarks.rs
use benchmark;
3. Build for Mobile
# Build Android APK
# Build iOS app
4. Run Benchmarks
Local device workflow (builds artifacts and writes the run spec; launch the app manually):
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-config.toml)
Example:
build - Build Mobile Apps
Cross-compile and package for mobile platforms:
|
Options:
--target <android|ios>- Platform to build for (required)--release- Build in release mode (default: debug)--output-dir <DIR>- Output directory for mobile artifacts (default:target/mobench/)--crate-path <PATH>- Path to the benchmark crate (default: auto-detect)--dry-run- Print what would be done without making changes--verbose/-v- Print verbose output including all commands
Examples:
# Build Android APK in release mode
# Build iOS xcframework
# Preview build without making changes
# Build with verbose output
# Build to custom output directory
Outputs:
- Android:
target/mobench/android/app/build/outputs/apk/debug/app-debug.apk - iOS:
target/mobench/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 mobile builds (no device run)--config <FILE>- Load run spec from config file--ios-app <FILE>- iOS .ipa or zipped .app for BrowserStack--ios-test-suite <FILE>- iOS XCUITest runner (.zip or .ipa)--output <FILE>- Save results to JSON file (default: run-summary.json)--summary-csv- Write CSV summary alongside JSON/Markdown--fetch- Fetch BrowserStack results after completion
Outputs:
- JSON summary (default:
run-summary.json) - Markdown summary (same base name,
.md) - CSV summary (same base name,
.csv, when--summary-csvis set)
Examples:
# Run locally (no BrowserStack devices specified)
# 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/mobench/ios/BenchRunner.ipa
plan - Generate Device Matrix
Create a template device matrix file:
Example:
Output: 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:
list - List Benchmarks
Show benchmarks discovered via #[benchmark]:
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:
compare - Compare Summaries
Compare two JSON run summaries and emit a Markdown report:
Configuration
Project Configuration (mobench.toml)
mobench automatically loads mobench.toml from the current directory or any parent directory:
[]
# Name of the benchmark crate
= "bench-mobile"
# Rust library name (typically crate name with hyphens replaced by underscores)
= "bench_mobile"
# Output directory for build artifacts (default: target/mobench/)
# output_dir = "target/mobench"
[]
# Android package name
= "com.example.bench"
# Minimum Android SDK version (default: 24)
= 24
# Target Android SDK version (default: 34)
= 34
[]
# iOS bundle identifier
= "com.example.bench"
# iOS deployment target version (default: 15.0)
= "15.0"
# Development team ID for code signing (optional)
# team_id = "YOUR_TEAM_ID"
[]
# Default benchmark function to run
= "my_crate::my_benchmark"
# Default number of benchmark iterations
= 100
# Default number of warmup iterations
= 10
CLI flags always override config file values when provided.
Run Config File Format (bench-config.toml)
For BrowserStack runs, you can also use a separate 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 Format (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:
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 --release
- name: Run benchmarks
env:
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
run: |
cargo mobench run \
--target android \
--function my_benchmark \
--devices "Google Pixel 7-13.0" \
--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 - Core SDK with timing harness, build automation, and codegen
- mobench-macros -
#[benchmark]proc macro
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