Skip to content

Commit 5b1021e

Browse files
authored
Merge pull request #891 from hatoo/remove-uncommon-timeunits
Avoid TenSeconds/TenMinutes time scales in summary output
2 parents b8cd846 + 2c95c1f commit 5b1021e

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/printer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ fn print_summary<W: Write>(
503503
timescale
504504
} else {
505505
// Use max latency (slowest request)
506-
TimeScale::from_f64(latency_stat.max())
506+
TimeScale::from_f64_summary(latency_stat.max())
507507
};
508508
writeln!(
509509
w,

src/timescale.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,24 @@ impl TimeScale {
130130
TimeScale::Nanosecond
131131
}
132132

133+
/// From seconds as f64 for summary output.
134+
/// TimeScale::TenSeconds and TimeScale::TenMinutes are not used for summary output. Because it is looked weird to see "10 sec" or "10 min" in summary output.
135+
pub fn from_f64_summary(seconds: f64) -> Self {
136+
for ts in &[
137+
TimeScale::Hour,
138+
TimeScale::Minute,
139+
TimeScale::Second,
140+
TimeScale::Millisecond,
141+
TimeScale::Microsecond,
142+
TimeScale::Nanosecond,
143+
] {
144+
if seconds > ts.as_secs_f64() {
145+
return *ts;
146+
}
147+
}
148+
TimeScale::Nanosecond
149+
}
150+
133151
pub fn from_elapsed(duration: Duration) -> Self {
134152
Self::from_f64(duration.as_secs_f64())
135153
}

0 commit comments

Comments
 (0)