Struct sc_sysinfo::Throughput

source ·
pub struct Throughput(_);
Expand description

Throughput as measured in bytes per second.

Implementations§

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)
}

Construct Self from mebibyte/s.

Construct Self from gibibyte/s.

Self as number of byte/s.

Self as number of kibibyte/s.

Examples found in repository?
src/sysinfo.rs (line 106)
98
99
100
101
102
103
104
105
106
107
108
	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)
		}
	}

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()
}

Self as number of gibibyte/s.

Examples found in repository?
src/sysinfo.rs (line 102)
98
99
100
101
102
103
104
105
106
107
108
	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)
		}
	}

Normalizes Self to use the largest unit possible.

Examples found in repository?
src/sysinfo.rs (line 113)
112
113
114
115
	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
		let (value, unit) = self.normalize();
		write!(f, "{:.2?} {}", value, unit)
	}

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
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.
Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Get a reference to the inner from the outer.

Get a mutable reference to the inner from the outer.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The counterpart to unchecked_from.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more