mobench-runner

Crates.iomobench-runner
lib.rsmobench-runner
version0.1.8
created_at2026-01-13 14:19:36.443308+00
updated_at2026-01-19 12:55:41.363081+00
descriptionLightweight benchmarking harness for mobile devices
homepage
repositoryhttps://github.com/worldcoin/mobile-bench-rs
max_upload_size
id2040272
size19,923
dcbuilder.eth (dcbuild3r)

documentation

https://docs.rs/mobench-runner

README

mobench-runner

Lightweight benchmarking harness for mobile devices.

This crate provides the core timing infrastructure for running benchmarks on mobile platforms (Android and iOS). It's designed to be embedded in mobile apps and provides accurate timing measurements with configurable iterations and warmup cycles.

Features

  • Accurate timing: High-precision timing measurements for benchmarks
  • Configurable: Set iterations and warmup cycles
  • Mobile-optimized: Designed for resource-constrained mobile environments
  • Serializable results: Results can be serialized with serde for transmission to host
  • No dependencies: Minimal dependencies for fast compilation

Usage

Add this to your Cargo.toml:

[dependencies]
mobench-runner = "0.1"

Basic Example

use mobench_runner::{BenchSpec, run_closure};

// Create a benchmark specification
let spec = BenchSpec {
    name: "my_benchmark".to_string(),
    iterations: 100,
    warmup: 10,
};

// Run a closure as a benchmark
let report = run_closure(spec, || {
    // Your benchmark code here
    let result = expensive_computation();
    std::hint::black_box(result); // Prevent optimization
    Ok(())
})?;

// Access timing results
println!("Mean: {} ns", report.mean_ns());
println!("Median: {} ns", report.median_ns());
println!("Min: {} ns", report.min_ns());
println!("Max: {} ns", report.max_ns());

With Error Handling

use mobench_runner::{BenchSpec, BenchError, run_closure};

fn my_benchmark() -> Result<(), String> {
    // Your code that might fail
    Ok(())
}

let spec = BenchSpec::new("my_benchmark", 50, 5)?;

let report = run_closure(spec, || {
    my_benchmark().map_err(|e| BenchError::Execution(e))
})?;

Types

BenchSpec

Specification for a benchmark run:

pub struct BenchSpec {
    pub name: String,      // Benchmark name
    pub iterations: u32,   // Number of iterations to run
    pub warmup: u32,       // Number of warmup iterations
}

BenchReport

Results from a benchmark run:

pub struct BenchReport {
    pub spec: BenchSpec,
    pub samples: Vec<BenchSample>,
}

Provides helper methods:

  • mean_ns() - Mean execution time
  • median_ns() - Median execution time
  • min_ns() - Minimum execution time
  • max_ns() - Maximum execution time
  • stddev_ns() - Standard deviation

BenchSample

Individual timing sample:

pub struct BenchSample {
    pub duration_ns: u64,  // Duration in nanoseconds
}

Use Cases

This crate is typically used as a dependency in larger benchmarking systems:

  1. Mobile benchmark harness: Embed in mobile apps to run benchmarks on real devices
  2. Cross-platform timing: Consistent timing API across platforms
  3. Remote benchmarking: Serialize results and send to analysis tools

Part of mobench

This crate is part of the mobench ecosystem for mobile benchmarking:

License

Licensed under the MIT License. See LICENSE.md for details.

Copyright (c) 2026 World Foundation

Commit count: 62

cargo fmt