mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-10-29 16:38:56 +00:00
Get rid of value_in
This commit is contained in:
1 parent
6b4e9eb5c2
commit
3d9e230b65
1 file changed
+7
-29
+7
-29
@@ -26,10 +26,6 @@ pub trait TimeQuantity {
|
||||
Time::new::<second>(0.0)
|
||||
}
|
||||
|
||||
fn value_in<U>(&self, u: U) -> f64
|
||||
where
|
||||
U: si::time::Unit + Conversion<f64, T = f64>;
|
||||
|
||||
fn suitable_unit(&self) -> TimeUnit;
|
||||
|
||||
fn format(&self, u: TimeUnit, precision: Option<usize>) -> String;
|
||||
@@ -38,13 +34,6 @@ pub trait TimeQuantity {
|
||||
}
|
||||
|
||||
impl TimeQuantity for Time {
|
||||
fn value_in<U>(&self, _u: U) -> f64
|
||||
where
|
||||
U: si::time::Unit + Conversion<f64, T = f64>,
|
||||
{
|
||||
self.get::<U>()
|
||||
}
|
||||
|
||||
fn suitable_unit(&self) -> TimeUnit {
|
||||
if *self < Time::new::<millisecond>(1.0) {
|
||||
TimeUnit::MicroSecond
|
||||
@@ -93,23 +82,12 @@ pub trait InformationQuantity {
|
||||
Information::new::<byte>(0.)
|
||||
}
|
||||
|
||||
fn value_in<U>(&self, u: U) -> f64
|
||||
where
|
||||
U: si::information::Unit + Conversion<f64, T = f64>;
|
||||
|
||||
fn to_string<U>(&self, u: U) -> String
|
||||
where
|
||||
U: si::information::Unit + Conversion<f64, T = f64>;
|
||||
}
|
||||
|
||||
impl InformationQuantity for Information {
|
||||
fn value_in<U>(&self, _u: U) -> f64
|
||||
where
|
||||
U: si::information::Unit + Conversion<f64, T = f64>,
|
||||
{
|
||||
self.get::<U>()
|
||||
}
|
||||
|
||||
fn to_string<U>(&self, u: U) -> String
|
||||
where
|
||||
U: si::information::Unit + Conversion<f64, T = f64>,
|
||||
@@ -128,7 +106,7 @@ pub trait UnsafeRawValue {
|
||||
|
||||
impl UnsafeRawValue for Time {
|
||||
fn unsafe_raw_value(&self) -> f64 {
|
||||
self.value_in(second)
|
||||
self.get::<second>()
|
||||
}
|
||||
|
||||
fn unsafe_from_raw_value(value: f64) -> Self {
|
||||
@@ -138,7 +116,7 @@ impl UnsafeRawValue for Time {
|
||||
|
||||
impl UnsafeRawValue for Information {
|
||||
fn unsafe_raw_value(&self) -> f64 {
|
||||
self.value_in(byte)
|
||||
self.get::<byte>()
|
||||
}
|
||||
|
||||
fn unsafe_from_raw_value(value: f64) -> Self {
|
||||
@@ -194,21 +172,21 @@ pub fn modified_zscores<Q: UnsafeRawValue>(values: &[Q]) -> Vec<f64> {
|
||||
#[test]
|
||||
fn test_time() {
|
||||
let time = Time::new::<millisecond>(123.4);
|
||||
assert_eq!(time.value_in(millisecond), 123.4);
|
||||
assert_eq!(time.get::<millisecond>(), 123.4);
|
||||
|
||||
let time_s = time.value_in(second);
|
||||
let time_s = time.get::<second>();
|
||||
approx::assert_relative_eq!(time_s, 0.1234);
|
||||
|
||||
let time_us = time.value_in(microsecond);
|
||||
let time_us = time.get::<microsecond>();
|
||||
approx::assert_relative_eq!(time_us, 123400.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_information() {
|
||||
let information = Information::new::<kibibyte>(8.);
|
||||
assert_eq!(information.value_in(byte), 8192.);
|
||||
assert_eq!(information.get::<byte>(), 8192.);
|
||||
|
||||
let information_kib = information.value_in(kibibyte);
|
||||
let information_kib = information.get::<kibibyte>();
|
||||
assert_eq!(information_kib, 8.);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user