Crates.io | carbonara |
lib.rs | carbonara |
version | 0.1.4 |
source | src |
created_at | 2024-06-05 15:22:07.802642 |
updated_at | 2024-11-05 12:59:33.965097 |
description | Calculate co2 Emmisions using https://www.green-coding.io/co2-formulas/ |
homepage | |
repository | https://github.com/sevki/carbonara |
max_upload_size | |
id | 1262892 |
size | 73,760 |
based on Green Coding Co2 formulas
use carbonara::{MeasurementConfig, BenchmarkExecutor, PowerSource, MeasurementError};
use std::time::Duration;
// Example usage with Auto power source detection, which will try RAPL first and then fall back to the ACPI power meter,
// if that also fails, it will use TDP based power estimation.
fn main() -> Result<(), MeasurementError> {
let config = MeasurementConfig {
duration: Duration::from_secs(5),
power_source: PowerSource::Auto,
sample_interval_ms: 100,
};
let executor = BenchmarkExecutor::new(config);
let result = executor.measure(|| {
// CPU-intensive workload
for _ in 0..1_000_000 {
let _ = (0..100).sum::<i32>();
}
})?;
println!("{} Measurement Results:", result.measurement_method);
println!("Total Energy: {:?}", result.total_energy);
println!("Average Power: {:?}", result.average_power);
println!("Peak Power: {:?}", result.peak_power);
println!("Duration: {:?}", result.duration);
println!("CO2e: {:.2} g", result.co2e(None));
Ok(())
}