Module timing

Module timing 

Source
Expand description

Lightweight benchmarking harness for mobile platforms.

This module provides the core timing infrastructure for the mobench ecosystem. It was previously a separate crate (mobench-runner) but has been consolidated into mobench-sdk for a simpler dependency graph.

The module is designed to be minimal and portable, with no platform-specific dependencies, making it suitable for compilation to Android and iOS targets.

§Overview

The timing module executes benchmark functions with:

  • Configurable warmup iterations
  • Precise nanosecond-resolution timing
  • Simple, serializable results

§Usage

Most users should use this via the higher-level crate::run_benchmark function or crate::BenchmarkBuilder. Direct usage is for custom integrations:

use mobench_sdk::timing::{BenchSpec, run_closure, TimingError};

// Define a benchmark specification
let spec = BenchSpec::new("my_benchmark", 100, 10)?;

// Run the benchmark
let report = run_closure(spec, || {
    // Your benchmark code
    let sum: u64 = (0..1000).sum();
    std::hint::black_box(sum);
    Ok(())
})?;

// Analyze results
let mean_ns = report.samples.iter()
    .map(|s| s.duration_ns)
    .sum::<u64>() / report.samples.len() as u64;

println!("Mean: {} ns", mean_ns);

§Types

TypeDescription
BenchSpecBenchmark configuration (name, iterations, warmup)
BenchSampleSingle timing measurement in nanoseconds
BenchReportComplete results with all samples
TimingErrorError conditions during benchmarking

§Feature Flags

This module is always available. When using mobench-sdk with default features, you also get build automation and template generation. For minimal binary size (e.g., on mobile targets), use the runner-only feature:

[dependencies]
mobench-sdk = { version = "0.1", default-features = false, features = ["runner-only"] }

Structs§

BenchReport
Complete benchmark report with all timing samples.
BenchSample
A single timing sample from a benchmark iteration.
BenchSpec
Benchmark specification defining what and how to benchmark.

Enums§

TimingError
Errors that can occur during benchmark execution.

Functions§

run_closure
Runs a benchmark by executing a closure repeatedly.
run_closure_with_setup
Runs a benchmark with setup that executes once before all iterations.
run_closure_with_setup_per_iter
Runs a benchmark with per-iteration setup.
run_closure_with_setup_teardown
Runs a benchmark with setup and teardown.