Skip to main content

Crate mobench

Crate mobench 

Source
Expand description

§mobench

Crates.io Documentation MIT License

Command-line tool for building and running Rust benchmarks on mobile devices.

§Overview

mobench is the CLI orchestrator for the mobench ecosystem. It handles:

  • Building - Compiles Rust code for Android/iOS and packages mobile apps
  • Running - Executes benchmarks locally or on BrowserStack devices
  • Reporting - Collects and formats benchmark results

§Installation

cargo install mobench

§Quick Start

# Initialize a benchmark project
cargo mobench init --target android --output bench-config.toml

# Build for Android
cargo mobench build --target android

# Build for iOS
cargo mobench build --target ios

# Run locally (no device required)
cargo mobench run --target android --function my_benchmark --local-only

# Run on BrowserStack (use --release for smaller APK uploads)
cargo mobench run --target android --function my_benchmark \
    --iterations 100 --warmup 10 --devices "Google Pixel 7-13.0" --release

§Commands

CommandDescription
initInitialize a new benchmark project
buildBuild mobile artifacts (APK/xcframework)
runExecute benchmarks locally or on devices
ci runRun standardized CI orchestration (summary.json, summary.md, results.csv)
doctorValidate local/CI prerequisites and configuration
config validateValidate run config + matrix contract
devices resolveResolve deterministic device sets from matrix/profile
fixture ...Fixture lifecycle helpers (init, build, verify, cache-key)
report ...Render markdown and publish sticky PR comments
listList discovered benchmark functions
fetchRetrieve results from BrowserStack
package-ipaPackage iOS app as IPA
package-xcuitestPackage XCUITest runner

§Output Directory

All build artifacts are written to target/mobench/ by default:

target/mobench/
├── android/           # Android project and APK
└── ios/               # iOS project, xcframework, and IPA

Use --output-dir to customize the output location.

§Configuration

Benchmarks can be configured via command-line arguments or a TOML config file:

target = "android"
function = "my_crate::my_benchmark"
iterations = 100
warmup = 10

[browserstack]
app_automate_username = "${BROWSERSTACK_USERNAME}"
app_automate_access_key = "${BROWSERSTACK_ACCESS_KEY}"
project = "my-project"

§BrowserStack Integration

The CLI integrates with BrowserStack App Automate for running benchmarks on real devices. Set credentials via environment variables:

export BROWSERSTACK_USERNAME="your_username"
export BROWSERSTACK_ACCESS_KEY="your_access_key"

§Crate Ecosystem

This crate is part of the mobench ecosystem:

  • mobench (this crate) - CLI tool
  • mobench-sdk - Core SDK with timing harness and build automation
  • mobench-macros - #[benchmark] proc macro

Note: The mobench-runner crate has been consolidated into mobench-sdk as its timing module.

§CLI Flags

Global flags available on all commands:

  • --dry-run - Preview what would be done without making changes
  • --verbose / -v - Enable detailed output showing all commands

§Modules

  • config - Configuration file support for mobench.toml

Modules§

config
Configuration file support for mobench.
summarize
Types and logic for the ci summarize command.

Structs§

DeviceSelection
Device input sources used by RunRequest.
ExtractedBenchmarkResult
Extracted benchmark result for a single device.
Report
Standardized output file locations produced by a run.
RunRequest
Programmatic request payload for running a mobench benchmark flow.
RunResult
Result of a programmatic mobench run request.

Enums§

MobileTarget
Mobile platform target for build/run operations.

Functions§

extract_benchmark_summary
Extract a unified summary from per-device benchmark results.
run
run_request
Executes a RunRequest by invoking the current mobench binary and normalizing outputs.