energy-bench 0.3.0

Methods for benchmarking the energy consumption of programs.
Documentation
use std::time::Duration;

use indexmap::IndexMap;

use crate::IdlePower;

#[derive(Debug)]
pub struct RunResult {
    pub runtime: Duration,
    pub energy: IndexMap<String, f32>,
}

impl RunResult {
    pub fn new(runtime: Duration, energy: IndexMap<String, f32>) -> Self {
        Self {
            runtime,
            energy,
        }
    }

    pub fn subtract_idle(&mut self, idle: &IdlePower) {
        self.energy.iter_mut().for_each(|(key, energy)| {
            *energy -= idle[key] * self.runtime.as_secs_f32();
            *energy = energy.max(0f32);
        });
    }
}