Struct sc_sysinfo::Throughput
source · pub struct Throughput(_);Expand description
Throughput as measured in bytes per second.
Implementations§
source§impl Throughput
impl Throughput
sourcepub fn from_kibs(kibs: f64) -> Throughput
pub fn from_kibs(kibs: f64) -> Throughput
Construct Self from kibibyte/s.
Examples found in repository?
src/sysinfo.rs (line 166)
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
pub(crate) fn benchmark<E>(
name: &str,
size: usize,
max_iterations: usize,
max_duration: Duration,
mut run: impl FnMut() -> Result<(), E>,
) -> Result<Throughput, E> {
// Run the benchmark once as a warmup to get the code into the L1 cache.
run()?;
// Then run it multiple times and average the result.
let timestamp = Instant::now();
let mut elapsed = Duration::default();
let mut count = 0;
for _ in 0..max_iterations {
run()?;
count += 1;
elapsed = timestamp.elapsed();
if elapsed >= max_duration {
break
}
}
let score = Throughput::from_kibs((size * count) as f64 / (elapsed.as_secs_f64() * 1024.0));
log::trace!(
"Calculated {} of {} in {} iterations in {}ms",
name,
score,
count,
elapsed.as_millis()
);
Ok(score)
}sourcepub fn from_mibs(mibs: f64) -> Throughput
pub fn from_mibs(mibs: f64) -> Throughput
Construct Self from mebibyte/s.
sourcepub fn from_gibs(gibs: f64) -> Throughput
pub fn from_gibs(gibs: f64) -> Throughput
Construct Self from gibibyte/s.
sourcepub fn as_mibs(&self) -> f64
pub fn as_mibs(&self) -> f64
Self as number of mebibyte/s.
Examples found in repository?
src/sysinfo.rs (line 104)
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
pub fn normalize(&self) -> (f64, Unit) {
let bs = self.0;
if bs >= GIBIBYTE {
(self.as_gibs(), Unit::GiBs)
} else if bs >= MEBIBYTE {
(self.as_mibs(), Unit::MiBs)
} else {
(self.as_kibs(), Unit::KiBs)
}
}
}
impl fmt::Display for Throughput {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (value, unit) = self.normalize();
write!(f, "{:.2?} {}", value, unit)
}
}
/// Serializes `Throughput` and uses MiBs as the unit.
pub fn serialize_throughput<S>(throughput: &Throughput, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_u64(throughput.as_mibs() as u64)
}
/// Serializes `Option<Throughput>` and uses MiBs as the unit.
pub fn serialize_throughput_option<S>(
maybe_throughput: &Option<Throughput>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
if let Some(throughput) = maybe_throughput {
return serializer.serialize_some(&(throughput.as_mibs() as u64))
}
serializer.serialize_none()
}Trait Implementations§
source§impl Clone for Throughput
impl Clone for Throughput
source§fn clone(&self) -> Throughput
fn clone(&self) -> Throughput
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for Throughput
impl Debug for Throughput
source§impl Display for Throughput
impl Display for Throughput
source§impl PartialEq<Throughput> for Throughput
impl PartialEq<Throughput> for Throughput
source§fn eq(&self, other: &Throughput) -> bool
fn eq(&self, other: &Throughput) -> bool
This method tests for
self and other values to be equal, and is used
by ==.source§impl PartialOrd<Throughput> for Throughput
impl PartialOrd<Throughput> for Throughput
source§fn partial_cmp(&self, other: &Throughput) -> Option<Ordering>
fn partial_cmp(&self, other: &Throughput) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moreimpl Copy for Throughput
impl StructuralPartialEq for Throughput
Auto Trait Implementations§
impl RefUnwindSafe for Throughput
impl Send for Throughput
impl Sync for Throughput
impl Unpin for Throughput
impl UnwindSafe for Throughput
Blanket Implementations§
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T, Outer> IsWrappedBy<Outer> for Twhere
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
impl<T, Outer> IsWrappedBy<Outer> for Twhere
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
source§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
source§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
The counterpart to
unchecked_from.