use subms::{SubMsGrowthClass, SubMsGrowthRecipe};
use crate::HdrHistogram;
const VALUE_CEILING: u64 = 1_000_000_000;
pub struct HdrGrowthRecipe {
hist: HdrHistogram,
rounds: usize,
records_per_round: usize,
bound_bytes: u64,
lcg: u64,
}
impl HdrGrowthRecipe {
pub fn new(significant_digits: u32, rounds: usize, records_per_round: usize) -> Self {
Self {
hist: HdrHistogram::new(significant_digits),
rounds,
records_per_round,
bound_bytes: ceiling_footprint_bytes(significant_digits),
lcg: 0x1234_5678,
}
}
}
fn ceiling_footprint_bytes(significant_digits: u32) -> u64 {
let mut probe = HdrHistogram::new(significant_digits);
probe.record(VALUE_CEILING - 1);
probe.footprint_bytes() as u64
}
impl SubMsGrowthRecipe for HdrGrowthRecipe {
fn name(&self) -> &str {
"subms-hdr-histogram"
}
fn op_name(&self) -> &str {
"record"
}
fn rounds(&self) -> usize {
self.rounds
}
fn ops_per_round(&self) -> usize {
self.records_per_round
}
fn op(&mut self, _round: usize, _i: usize) {
self.lcg = self.lcg.wrapping_mul(6364136223846793005).wrapping_add(1);
let v = (self.lcg >> 33) % VALUE_CEILING;
self.hist.record(v.max(1));
}
fn memory_bytes(&mut self) -> u64 {
self.hist.footprint_bytes() as u64
}
fn live_bytes(&mut self) -> u64 {
self.hist.footprint_bytes() as u64
}
fn structures(&mut self) -> Vec<(String, u64)> {
vec![("records".to_string(), self.hist.count())]
}
fn expected(&self) -> (SubMsGrowthClass, f64) {
(SubMsGrowthClass::Bounded, self.bound_bytes as f64 * 1.01)
}
fn compact(&self) -> bool {
true
}
}
#[cfg(test)]
#[path = "growth_tests.rs"]
mod tests;