pub struct NormalizedBwConfig {
pub mean: Option<Bandwidth>,
pub std_dev: Option<Bandwidth>,
pub upper_bound: Option<Bandwidth>,
pub lower_bound: Option<Bandwidth>,
pub duration: Option<Duration>,
pub step: Option<Duration>,
pub seed: Option<u64>,
}Expand description
The configuration struct for NormalizedBw.
See NormalizedBw for more details.
Fields§
§mean: Option<Bandwidth>§std_dev: Option<Bandwidth>§upper_bound: Option<Bandwidth>§lower_bound: Option<Bandwidth>§duration: Option<Duration>§step: Option<Duration>§seed: Option<u64>Implementations§
Source§impl NormalizedBwConfig
impl NormalizedBwConfig
Sourcepub fn mean(self, mean: Bandwidth) -> Self
pub fn mean(self, mean: Bandwidth) -> Self
Sets the mean
If the mean is not set, 12Mbps will be used.
Sourcepub fn std_dev(self, std_dev: Bandwidth) -> Self
pub fn std_dev(self, std_dev: Bandwidth) -> Self
Sets the standard deviation
If the standard deviation is not set, 0Mbps will be used.
Sourcepub fn upper_bound(self, upper_bound: Bandwidth) -> Self
pub fn upper_bound(self, upper_bound: Bandwidth) -> Self
Sets the upper bound
If the upper bound is not set, the upper bound will be the one of Bandwidth.
Sourcepub fn lower_bound(self, lower_bound: Bandwidth) -> Self
pub fn lower_bound(self, lower_bound: Bandwidth) -> Self
Sets the lower bound
If the lower bound is not set, the lower bound will be the one of Bandwidth.
Sourcepub fn duration(self, duration: Duration) -> Self
pub fn duration(self, duration: Duration) -> Self
Sets the total duration of the trace
If the total duration is not set, 1 second will be used.
Sourcepub fn step(self, step: Duration) -> Self
pub fn step(self, step: Duration) -> Self
Sets the duration of each value
If the step is not set, 1ms will be used.
Sourcepub fn seed(self, seed: u64) -> Self
pub fn seed(self, seed: u64) -> Self
Set the seed for a random generator
If the seed is not set, 42 will be used.
Sourcepub fn random_seed(self) -> Self
pub fn random_seed(self) -> Self
Allows to use a randomly generated seed
This is equivalent to: self.seed(rand::random())
Sourcepub fn build(self) -> NormalizedBw
pub fn build(self) -> NormalizedBw
Creates a new NormalizedBw corresponding to this config.
The created model will use StdRng as source of randomness (the call is equivalent to self.build_with_rng::<StdRng>()).
It should be sufficient for most cases, but StdRng is not a portable random number generator,
so one may want to use a portable random number generator like ChaCha,
to this end one can use build_with_rng.
Sourcepub fn build_with_rng<Rng: SeedableRng + RngCore>(self) -> NormalizedBw<Rng>
pub fn build_with_rng<Rng: SeedableRng + RngCore>(self) -> NormalizedBw<Rng>
Creates a new NormalizedBw corresponding to this config.
Unlike build, this method let you choose the random generator.
§Example
let normal_bw = NormalizedBwConfig::new()
.mean(Bandwidth::from_mbps(12))
.std_dev(Bandwidth::from_mbps(1))
.duration(Duration::from_millis(3))
.seed(42);
let mut default_build = normal_bw.clone().build();
let mut std_build = normal_bw.clone().build_with_rng::<StdRng>();
// ChaCha is deterministic and portable, unlike StdRng
let mut chacha_build = normal_bw.clone().build_with_rng::<ChaCha20Rng>();
for cha in [12044676, 11754367, 11253775] {
let default = default_build.next_bw();
let std = std_build.next_bw();
let chacha = chacha_build.next_bw();
assert!(default.is_some());
assert_eq!(default, std);
assert_ne!(default, chacha);
assert_eq!(chacha, Some((Bandwidth::from_bps(cha), Duration::from_millis(1))));
}
assert_eq!(default_build.next_bw(), None);
assert_eq!(std_build.next_bw(), None);
assert_eq!(chacha_build.next_bw(), None);Source§impl NormalizedBwConfig
impl NormalizedBwConfig
Sourcepub fn build_truncated(self) -> NormalizedBw
pub fn build_truncated(self) -> NormalizedBw
This is another implementation for converting NormalizedBwConfig into NormalizedBw, where the impact
of truncation (lower_bound and upper_bound field) on the mathematical expectation of the distribution
is taking account by modifying the center of the distribution.
§Examples
let normal_bw = NormalizedBwConfig::new()
.mean(Bandwidth::from_mbps(12))
.std_dev(Bandwidth::from_mbps(12))
.duration(Duration::from_secs(100))
.step(Duration::from_millis(1))
.seed(42);
let mut default_build = normal_bw.clone().build();
let mut truncate_build = normal_bw.clone().build_truncated();
fn avg_mbps(mut model: impl BwTrace) -> f64{
let mut count = 0;
std::iter::from_fn( move ||{
model.next_bw().map(|b| b.0.as_gbps_f64() * 1000.0)
}).inspect(|_| count += 1).sum::<f64>() / count as f64
}
assert_eq!(avg_mbps(default_build), 12.974758080079994); // significantly higher than the expected mean
assert_eq!(avg_mbps(truncate_build), 11.97642456625989);
let normal_bw = NormalizedBwConfig::new()
.mean(Bandwidth::from_mbps(12))
.std_dev(Bandwidth::from_mbps(12))
.duration(Duration::from_secs(100))
.lower_bound(Bandwidth::from_mbps(8))
.upper_bound(Bandwidth::from_mbps(20))
.step(Duration::from_millis(1))
.seed(42);
let mut default_build = normal_bw.clone().build();
let mut truncate_build = normal_bw.clone().build_truncated();
assert_eq!(avg_mbps(default_build), 13.221356471729928); // significantly higher than the expected mean
assert_eq!(avg_mbps(truncate_build), 11.978819427569897);
Sourcepub fn build_truncated_with_rng<Rng: SeedableRng + RngCore>(
self,
) -> NormalizedBw<Rng>
pub fn build_truncated_with_rng<Rng: SeedableRng + RngCore>( self, ) -> NormalizedBw<Rng>
Similar to build_truncated but let you choose the random generator.
See build for details about the reason for using another random number generator than StdRng.
Trait Implementations§
Source§impl BwTraceConfig for NormalizedBwConfig
impl BwTraceConfig for NormalizedBwConfig
fn into_model(self: Box<NormalizedBwConfig>) -> Box<dyn BwTrace>
Source§impl Clone for NormalizedBwConfig
impl Clone for NormalizedBwConfig
Source§fn clone(&self) -> NormalizedBwConfig
fn clone(&self) -> NormalizedBwConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NormalizedBwConfig
impl Debug for NormalizedBwConfig
Source§impl Default for NormalizedBwConfig
impl Default for NormalizedBwConfig
Source§fn default() -> NormalizedBwConfig
fn default() -> NormalizedBwConfig
Source§impl<'de> Deserialize<'de> for NormalizedBwConfigwhere
NormalizedBwConfig: Default,
impl<'de> Deserialize<'de> for NormalizedBwConfigwhere
NormalizedBwConfig: Default,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Forever for NormalizedBwConfig
impl Forever for NormalizedBwConfig
fn forever(self) -> RepeatedBwPatternConfig
Auto Trait Implementations§
impl Freeze for NormalizedBwConfig
impl RefUnwindSafe for NormalizedBwConfig
impl Send for NormalizedBwConfig
impl Sync for NormalizedBwConfig
impl Unpin for NormalizedBwConfig
impl UnwindSafe for NormalizedBwConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Serialize for T
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>
fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.