mobench_sdk/
lib.rs

1//! Mobile Benchmark SDK for Rust
2//!
3//! `bench-sdk` is a library for benchmarking Rust functions on real mobile devices
4//! (Android and iOS) via BrowserStack. It provides a simple API similar to criterion.rs
5//! but targets mobile platforms.
6//!
7//! # Quick Start
8//!
9//! 1. Add bench-sdk to your project:
10//! ```toml
11//! [dependencies]
12//! bench-sdk = "0.1"
13//! ```
14//!
15//! 2. Mark functions with `#[benchmark]`:
16//! ```ignore
17//! use mobench_sdk::benchmark;
18//!
19//! #[benchmark]
20//! fn my_expensive_operation() {
21//!     // Your code here
22//!     let result = compute_something();
23//!     std::hint::black_box(result);
24//! }
25//! ```
26//!
27//! 3. Initialize mobile project:
28//! ```bash
29//! cargo bench-sdk init --target android
30//! ```
31//!
32//! 4. Build and run:
33//! ```bash
34//! cargo bench-sdk build --target android
35//! cargo bench-sdk run my_expensive_operation --target android
36//! ```
37//!
38//! # Architecture
39//!
40//! The SDK consists of several components:
41//!
42//! - **Registry**: Discovers functions marked with `#[benchmark]` at runtime
43//! - **Runner**: Executes benchmarks and collects timing data
44//! - **Builders**: Automates building Android/iOS apps
45//! - **Codegen**: Generates mobile app templates
46//!
47//! # Example: Programmatic Usage
48//!
49//! ```ignore
50//! use mobench_sdk::{BenchmarkBuilder, BenchSpec};
51//!
52//! fn main() -> Result<(), mobench_sdk::BenchError> {
53//!     // Using the builder pattern
54//!     let report = BenchmarkBuilder::new("my_benchmark")
55//!         .iterations(100)
56//!         .warmup(10)
57//!         .run()?;
58//!
59//!     println!("Samples: {}", report.samples.len());
60//!
61//!     // Or using BenchSpec directly
62//!     let spec = BenchSpec {
63//!         name: "my_benchmark".to_string(),
64//!         iterations: 50,
65//!         warmup: 5,
66//!     };
67//!     let report = mobench_sdk::run_benchmark(spec)?;
68//!
69//!     Ok(())
70//! }
71//! ```
72
73// Public modules
74pub mod builders;
75pub mod codegen;
76pub mod registry;
77pub mod runner;
78pub mod types;
79
80// Re-export the benchmark macro from bench-macros
81pub use mobench_macros::benchmark;
82
83// Re-export key types for convenience
84pub use registry::{BenchFunction, discover_benchmarks, find_benchmark, list_benchmark_names};
85pub use runner::{BenchmarkBuilder, run_benchmark};
86pub use types::{
87    BenchError, BenchSample, BenchSpec, BuildConfig, BuildProfile, BuildResult, InitConfig,
88    RunnerReport, Target,
89};
90
91// Re-export mobench-runner types for backward compatibility
92pub use mobench_runner;
93
94/// Library version
95pub const VERSION: &str = env!("CARGO_PKG_VERSION");
96
97#[cfg(test)]
98mod tests {
99    use super::*;
100
101    #[test]
102    fn test_version_is_set() {
103        assert!(!VERSION.is_empty());
104    }
105
106    #[test]
107    fn test_discover_benchmarks_compiles() {
108        // This test just ensures the function is accessible
109        let _benchmarks = discover_benchmarks();
110    }
111}