oxigdal_bench/lib.rs
1//! OxiGDAL Benchmarking and Profiling Suite
2//!
3//! `oxigdal-bench` provides comprehensive performance profiling and benchmarking
4//! capabilities for the OxiGDAL geospatial library ecosystem.
5//!
6//! # Features
7//!
8//! - **CPU Profiling**: Profile CPU usage with flamegraph generation
9//! - **Memory Profiling**: Track memory usage and detect leaks
10//! - **Benchmark Scenarios**: Predefined scenarios for common operations
11//! - **Performance Comparison**: Compare performance across implementations
12//! - **Regression Detection**: Detect performance regressions against baselines
13//! - **Report Generation**: Generate HTML, JSON, CSV, and Markdown reports
14//!
15//! # Example
16//!
17//! ```rust,no_run
18//! use oxigdal_bench::profiler::{CpuProfiler, CpuProfilerConfig};
19//! use oxigdal_bench::scenarios::{ScenarioBuilder, ScenarioRunner};
20//! use oxigdal_bench::report::{BenchmarkReport, ReportFormat};
21//!
22//! // Create a custom benchmark scenario
23//! let scenario = ScenarioBuilder::new("my_benchmark")
24//! .description("Test raster processing")
25//! .execute(|| {
26//! // Your benchmark code here
27//! Ok(())
28//! })
29//! .build();
30//!
31//! // Run the scenario
32//! let mut runner = ScenarioRunner::new();
33//! runner.add_scenario(scenario);
34//! runner.run_all().expect("Failed to run benchmarks");
35//!
36//! // Generate a report
37//! let mut report = BenchmarkReport::new("My Benchmark Report");
38//! report.add_scenario_results(runner.results().to_vec());
39//! report.generate("report.html", ReportFormat::Html)
40//! .expect("Failed to generate report");
41//! ```
42//!
43//! # Scenario Modules
44//!
45//! - `scenarios::raster`: Raster operation benchmarks (requires `raster` feature)
46//! - `scenarios::vector`: Vector operation benchmarks (requires `vector` feature)
47//! - [`scenarios::io`]: I/O performance benchmarks
48//! - `scenarios::cloud`: Cloud storage benchmarks (requires `cloud` feature)
49//! - `scenarios::ml`: ML inference benchmarks (requires `ml` feature)
50//!
51//! # Profiling
52//!
53//! The [`profiler`] module provides CPU and memory profiling utilities:
54//!
55//! ```rust,no_run
56//! use oxigdal_bench::profiler::{profile_cpu, CpuProfilerConfig};
57//!
58//! let config = CpuProfilerConfig {
59//! frequency: 100,
60//! generate_flamegraph: true,
61//! ..Default::default()
62//! };
63//!
64//! let (result, report) = profile_cpu(|| {
65//! // Code to profile
66//! 42
67//! }, config).expect("Profiling failed");
68//!
69//! println!("Profiling duration: {:?}", report.duration);
70//! ```
71
72#![deny(clippy::unwrap_used)]
73#![deny(clippy::panic)]
74#![warn(missing_docs)]
75#![warn(clippy::expect_used)]
76#![allow(unexpected_cfgs)]
77
78// Re-export commonly used types
79pub use error::{BenchError, Result};
80
81// Core modules
82pub mod comparison;
83pub mod error;
84pub mod profiler;
85pub mod regression;
86pub mod report;
87pub mod scenarios;
88
89// Version information
90/// The version of this crate.
91pub const VERSION: &str = env!("CARGO_PKG_VERSION");
92
93/// The name of this crate.
94pub const CRATE_NAME: &str = env!("CARGO_PKG_NAME");
95
96// Prelude module for convenient imports
97pub mod prelude {
98 //! Prelude module with commonly used types and traits.
99
100 pub use crate::comparison::{Comparison, ComparisonSuite, Implementation};
101 pub use crate::error::{BenchError, Result};
102 pub use crate::profiler::{
103 CpuProfiler, CpuProfilerConfig, MemoryProfiler, MemoryProfilerConfig, SystemMonitor,
104 profile_cpu, profile_memory,
105 };
106 pub use crate::regression::{
107 Baseline, BaselineStore, RegressionConfig, RegressionDetector, RegressionReport,
108 RegressionResult, RegressionSeverity,
109 };
110 pub use crate::report::{BenchmarkReport, ReportBuilder, ReportFormat};
111 pub use crate::scenarios::{
112 BenchmarkScenario, CustomScenario, ScenarioBuilder, ScenarioResult, ScenarioRunner,
113 };
114}
115
116#[cfg(test)]
117mod tests {
118 use super::*;
119
120 #[test]
121 fn test_version() {
122 assert!(!VERSION.is_empty());
123 assert_eq!(CRATE_NAME, "oxigdal-bench");
124 }
125}