-
-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved
types::Second
and types::Unit
to new unit
module
Also review feedback.
- Loading branch information
1 parent
f0b6f13
commit 3aa26a3
Showing
17 changed files
with
73 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ pub mod outlier_detection; | |
pub mod shell; | ||
pub mod timer; | ||
pub mod types; | ||
pub mod units; | ||
pub mod warnings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use hyperfine::types::Second; | ||
use hyperfine::units::Second; | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
pub struct CPUTimes { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/// This module contains common units. | ||
|
||
/// Type alias for unit of time | ||
pub type Second = f64; | ||
|
||
/// Supported time units | ||
#[derive(Debug, Clone, Copy, PartialEq)] | ||
pub enum Unit { | ||
Second, | ||
MilliSecond, | ||
} | ||
|
||
impl Unit { | ||
/// The abbreviation of the Unit. | ||
pub fn short_name(&self) -> String { | ||
match *self { | ||
Unit::Second => String::from("s"), | ||
Unit::MilliSecond => String::from("ms"), | ||
} | ||
} | ||
|
||
/// Returns the Second value formatted for the Unit. | ||
pub fn format(&self, value: Second) -> String { | ||
match *self { | ||
Unit::Second => format!("{:.3}", value), | ||
Unit::MilliSecond => format!("{:.1}", value * 1e3), | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_unit_short_name() { | ||
assert_eq!("s", Unit::Second.short_name()); | ||
assert_eq!("ms", Unit::MilliSecond.short_name()); | ||
} | ||
|
||
// Note - the values are rounded when formatted. | ||
#[test] | ||
fn test_unit_format() { | ||
let value: Second = 123.456789; | ||
assert_eq!("123.457", Unit::Second.format(value)); | ||
assert_eq!("123456.8", Unit::MilliSecond.format(value)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters