mobench-sdk-0.1.1 has been yanked.
Mobile Benchmark SDK for Rust
bench-sdk is a library for benchmarking Rust functions on real mobile devices
(Android and iOS) via BrowserStack. It provides a simple API similar to criterion.rs
but targets mobile platforms.
Quick Start
- Add bench-sdk to your project:
[]
= "0.1"
- Mark functions with
#[benchmark]:
use mobench_sdk::benchmark;
#[benchmark]
fn my_expensive_operation() {
// Your code here
let result = compute_something();
std::hint::black_box(result);
}
- Initialize mobile project:
- Build and run:
Architecture
The SDK consists of several components:
- Registry: Discovers functions marked with
#[benchmark]at runtime - Runner: Executes benchmarks and collects timing data
- Builders: Automates building Android/iOS apps
- Codegen: Generates mobile app templates
Example: Programmatic Usage
use mobench_sdk::{BenchmarkBuilder, BenchSpec};
fn main() -> Result<(), mobench_sdk::BenchError> {
// Using the builder pattern
let report = BenchmarkBuilder::new("my_benchmark")
.iterations(100)
.warmup(10)
.run()?;
println!("Samples: {}", report.samples.len());
// Or using BenchSpec directly
let spec = BenchSpec {
name: "my_benchmark".to_string(),
iterations: 50,
warmup: 5,
};
let report = mobench_sdk::run_benchmark(spec)?;
Ok(())
}