git_perf/defaults.rs
1//! Centralized default values for git-perf configuration.
2//!
3//! This module defines all default values used throughout the application
4//! to avoid magic numbers scattered in the codebase. These defaults are used
5//! as fallback values when configuration is not explicitly provided.
6
7// ============================================================================
8// Audit Configuration Defaults
9// ============================================================================
10
11/// Default minimum number of historical measurements required for audit.
12///
13/// When auditing a measurement, at least this many historical data points
14/// are required to establish a statistical baseline. If fewer measurements
15/// are available, the audit will be skipped with a warning.
16///
17/// This value is used when neither CLI options nor configuration file
18/// specify `min_measurements`.
19pub const DEFAULT_MIN_MEASUREMENTS: u16 = 2;
20
21/// Default sigma (standard deviation threshold) for statistical significance.
22///
23/// Measurements are considered significantly different if their z-score
24/// exceeds this threshold. A value of 4.0 means that the measurement must
25/// be more than 4 standard deviations (or MAD units) away from the mean
26/// to be flagged as a regression.
27///
28/// This value is used when neither CLI options nor configuration file
29/// specify `sigma`.
30pub const DEFAULT_SIGMA: f64 = 4.0;
31
32// ============================================================================
33// Backoff Configuration Defaults
34// ============================================================================
35
36/// Default maximum elapsed time (in seconds) for exponential backoff retries.
37///
38/// When operations fail (e.g., network requests for git operations), the system
39/// will retry with exponential backoff up to this maximum duration before
40/// giving up.
41///
42/// This value is used when configuration file does not specify
43/// `backoff.max_elapsed_seconds`.
44pub const DEFAULT_BACKOFF_MAX_ELAPSED_SECONDS: u64 = 60;
45
46// ============================================================================
47// Epoch Configuration Defaults
48// ============================================================================
49
50/// Default epoch value when no epoch is configured.
51///
52/// An epoch is a commit hash that marks the start of a new measurement series.
53/// When measurements are incompatible between different periods (e.g., after
54/// a significant change to the benchmark), a new epoch can be set to separate
55/// the data.
56///
57/// A value of 0 indicates no epoch boundary, meaning all measurements are
58/// considered part of the same series.
59pub const DEFAULT_EPOCH: u32 = 0;
60
61// ============================================================================
62// Git Configuration Defaults
63// ============================================================================
64
65// Default remote name for git-perf notes:
66// This is already defined as GIT_PERF_REMOTE in git/git_definitions.rs
67// and should not be duplicated. The actual value is "git-perf-origin".
68// See git/git_definitions.rs:28 for the implementation.
69
70// ============================================================================
71// Helper Functions
72// ============================================================================
73
74/// Returns the default minimum number of measurements for audit.
75#[inline]
76#[must_use]
77pub const fn default_min_measurements() -> u16 {
78 DEFAULT_MIN_MEASUREMENTS
79}
80
81/// Returns the default sigma threshold for statistical significance.
82#[inline]
83#[must_use]
84pub const fn default_sigma() -> f64 {
85 DEFAULT_SIGMA
86}
87
88/// Returns the default backoff max elapsed seconds.
89#[inline]
90#[must_use]
91pub const fn default_backoff_max_elapsed_seconds() -> u64 {
92 DEFAULT_BACKOFF_MAX_ELAPSED_SECONDS
93}
94
95/// Returns the default epoch value.
96#[inline]
97#[must_use]
98pub const fn default_epoch() -> u32 {
99 DEFAULT_EPOCH
100}
101
102#[cfg(test)]
103mod tests {
104 use super::*;
105
106 #[test]
107 fn test_default_min_measurements() {
108 assert_eq!(DEFAULT_MIN_MEASUREMENTS, 2);
109 assert_eq!(default_min_measurements(), 2);
110 }
111
112 #[test]
113 fn test_default_sigma() {
114 assert_eq!(DEFAULT_SIGMA, 4.0);
115 assert_eq!(default_sigma(), 4.0);
116 }
117
118 #[test]
119 fn test_default_backoff_max_elapsed_seconds() {
120 assert_eq!(DEFAULT_BACKOFF_MAX_ELAPSED_SECONDS, 60);
121 assert_eq!(default_backoff_max_elapsed_seconds(), 60);
122 }
123
124 #[test]
125 fn test_default_epoch() {
126 assert_eq!(DEFAULT_EPOCH, 0);
127 assert_eq!(default_epoch(), 0);
128 }
129}