diskann_benchmark_core/utils.rs
1/*
2 * Copyright (c) Microsoft Corporation.
3 * Licensed under the MIT license.
4 */
5
6use diskann_benchmark_runner::utils::percentiles::AsF64Lossy;
7
8/// Computes the arithmetic mean of an iterator of values, returning `0.0` when empty.
9pub fn average_all<I>(x: I) -> f64
10where
11 I: IntoIterator<Item: AsF64Lossy>,
12{
13 let (sum, count) = x.into_iter().fold((0.0, 0usize), |(sum, count), partial| {
14 (sum + partial.as_f64_lossy(), count + 1)
15 });
16
17 if count == 0 { 0.0 } else { sum / count as f64 }
18}