| Crates.io | mobench-runner |
| lib.rs | mobench-runner |
| version | 0.1.8 |
| created_at | 2026-01-13 14:19:36.443308+00 |
| updated_at | 2026-01-19 12:55:41.363081+00 |
| description | Lightweight benchmarking harness for mobile devices |
| homepage | |
| repository | https://github.com/worldcoin/mobile-bench-rs |
| max_upload_size | |
| id | 2040272 |
| size | 19,923 |
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.
Add this to your Cargo.toml:
[dependencies]
mobench-runner = "0.1"
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());
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))
})?;
BenchSpecSpecification 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
}
BenchReportResults from a benchmark run:
pub struct BenchReport {
pub spec: BenchSpec,
pub samples: Vec<BenchSample>,
}
Provides helper methods:
mean_ns() - Mean execution timemedian_ns() - Median execution timemin_ns() - Minimum execution timemax_ns() - Maximum execution timestddev_ns() - Standard deviationBenchSampleIndividual timing sample:
pub struct BenchSample {
pub duration_ns: u64, // Duration in nanoseconds
}
This crate is typically used as a dependency in larger benchmarking systems:
This crate is part of the mobench ecosystem for mobile benchmarking:
#[benchmark]Licensed under the MIT License. See LICENSE.md for details.
Copyright (c) 2026 World Foundation