elara_bench/lib.rs
1//! # ELARA Benchmark Suite
2//!
3//! Production-grade benchmark suite for the ELARA Protocol using criterion for
4//! statistical analysis and performance tracking.
5//!
6//! ## Overview
7//!
8//! This crate provides comprehensive benchmarks for all critical components:
9//! - Wire protocol encoding/decoding
10//! - Cryptographic operations
11//! - State reconciliation
12//! - Time engine operations
13//!
14//! ## Usage
15//!
16//! Run all benchmarks:
17//! ```bash
18//! cargo bench --package elara-bench
19//! ```
20//!
21//! Run specific benchmark:
22//! ```bash
23//! cargo bench --package elara-bench --bench wire_protocol
24//! ```
25//!
26//! ## Configuration
27//!
28//! Benchmarks can be configured via `BenchmarkConfig` for custom scenarios.
29
30use std::time::Duration;
31
32/// Configuration for benchmark execution
33#[derive(Debug, Clone)]
34pub struct BenchmarkConfig {
35 /// Number of iterations for warmup
36 pub warmup_iterations: usize,
37 /// Duration of warmup phase
38 pub warmup_time: Duration,
39 /// Duration of measurement phase
40 pub measurement_time: Duration,
41 /// Sample size for statistical analysis
42 pub sample_size: usize,
43}
44
45impl Default for BenchmarkConfig {
46 fn default() -> Self {
47 Self {
48 warmup_iterations: 100,
49 warmup_time: Duration::from_secs(3),
50 measurement_time: Duration::from_secs(5),
51 sample_size: 100,
52 }
53 }
54}
55
56impl BenchmarkConfig {
57 /// Create a quick benchmark configuration for CI
58 pub fn quick() -> Self {
59 Self {
60 warmup_iterations: 10,
61 warmup_time: Duration::from_secs(1),
62 measurement_time: Duration::from_secs(2),
63 sample_size: 50,
64 }
65 }
66
67 /// Create a thorough benchmark configuration for baseline establishment
68 pub fn thorough() -> Self {
69 Self {
70 warmup_iterations: 500,
71 warmup_time: Duration::from_secs(10),
72 measurement_time: Duration::from_secs(30),
73 sample_size: 200,
74 }
75 }
76}
77
78/// Standard payload sizes for benchmarking (64B to 1KB for wire protocol)
79pub const PAYLOAD_SIZES: &[usize] = &[64, 256, 1024, 4096, 16384];
80
81/// Wire protocol payload sizes (limited by MTU)
82pub const WIRE_PAYLOAD_SIZES: &[usize] = &[64, 256, 1024];
83
84/// Standard event counts for state benchmarks
85pub const EVENT_COUNTS: &[usize] = &[10, 100, 1000];