///|
pub struct BenchmarkResult {
  workload : String
  iterations : Int
  checksum : Double
  total_duty_w : Double
  total_residual_w : Double
} derive(Debug)

///|
pub fn run_benchmark_workload(iterations : Int) -> BenchmarkResult {
  let count = iterations.max(0)
  let mut checksum = 0.0
  let mut total_duty = 0.0
  let mut total_residual = 0.0
  for i in 0.. String {
  "workload=\{result.workload}, iterations=\{result.iterations}, checksum=\{result.checksum}, residual=\{result.total_residual_w}"
}

///|
pub fn benchmark_checksum_is_stable(
  first : BenchmarkResult,
  second : BenchmarkResult,
  tolerance : Double,
) -> Bool {
  first.iterations == second.iterations &&
  (first.checksum - second.checksum).abs() <= tolerance.abs()
}

///|
pub fn benchmark_average_duty(result : BenchmarkResult) -> Double {
  if result.iterations <= 0 {
    0.0
  } else {
    result.total_duty_w / result.iterations.to_double()
  }
}

///|
pub fn benchmark_average_residual(result : BenchmarkResult) -> Double {
  if result.iterations <= 0 {
    0.0
  } else {
    result.total_residual_w / result.iterations.to_double()
  }
}

///|
pub fn benchmark_workload_name() -> String {
  "water-heater-cooler-exchanger"
}