siteone-crawler 2.5.1

Website crawler and QA toolkit in Rust for security, performance, SEO, and accessibility audits, offline cloning, markdown export, sitemap generation, cache warming, and CI/CD gating — one dependency-free binary for all major platforms, 10 tools in one.
Documentation
// SiteOne Crawler - BaseAnalyzer
// (c) Jan Reges <jan.reges@siteone.cz>

use std::collections::HashMap;
use std::time::Instant;

/// Common state and methods shared by all analyzers.
/// Embed this as a field in each concrete analyzer struct.
#[derive(Debug, Default)]
pub struct BaseAnalyzer {
    /// Total exec times of analyzer methods: "ClassName::method" -> seconds
    pub exec_times: HashMap<String, f64>,
    /// Total exec counts of analyzer methods: "ClassName::method" -> count
    pub exec_counts: HashMap<String, usize>,
}

impl BaseAnalyzer {
    pub fn new() -> Self {
        Self::default()
    }

    /// Measure and increment exec time and count of an analyzer method.
    pub fn measure_exec_time(&mut self, class: &str, method: &str, start_time: Instant) {
        let elapsed = start_time.elapsed().as_secs_f64();
        let key = format!("{}::{}", class, method);

        *self.exec_times.entry(key.clone()).or_insert(0.0) += elapsed;
        *self.exec_counts.entry(key).or_insert(0) += 1;
    }

    pub fn get_exec_times(&self) -> &HashMap<String, f64> {
        &self.exec_times
    }

    pub fn get_exec_counts(&self) -> &HashMap<String, usize> {
        &self.exec_counts
    }
}