Crate mobench_sdk

Crate mobench_sdk 

Source
Expand description

Mobile Benchmark SDK for Rust

mobench-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

  1. Add mobench-sdk to your project:
[dependencies]
mobench-sdk = "0.1"
  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);
}
  1. Initialize mobile project:
cargo mobench init --target android
  1. Build and run:
cargo mobench build --target android
cargo mobench run --target android --function my_expensive_operation

§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(())
}

Re-exports§

pub use registry::BenchFunction;
pub use registry::discover_benchmarks;
pub use registry::find_benchmark;
pub use registry::list_benchmark_names;
pub use runner::BenchmarkBuilder;
pub use runner::run_benchmark;
pub use types::BenchError;
pub use types::BuildConfig;
pub use types::BuildProfile;
pub use types::BuildResult;
pub use types::InitConfig;
pub use types::Target;
pub use mobench_runner;

Modules§

builders
Build automation for mobile platforms
codegen
Code generation and template management
registry
Benchmark function registry
runner
Benchmark execution runtime
types
Core types for mobench-sdk

Structs§

BenchSample
BenchSpec
RunnerReport

Constants§

VERSION
Library version

Attribute Macros§

benchmark
Marks a function as a benchmark.