Skip to content

Commit 1d3174b

Browse files
Cardosaumlucab
andauthored
chore(histogram): Simplify code by using std lib method (#547)
* chore(histogram): Simplify code by using std lib method Leverage existing standard library method to simplify implementation. No changes to public API or MSRV. Signed-off-by: Matheus <[email protected]> * refactor(histogram): Remove `duration_to_seconds` function Signed-off-by: Matheus <[email protected]> * tests(histogram): Remove `duration_to_second` test After removing the aforementioned method in a previous commit, this test became obsolete. Signed-off-by: Matheus <[email protected]> --------- Signed-off-by: Matheus <[email protected]> Co-authored-by: Luca Bruno <[email protected]>
1 parent 53d3066 commit 1d3174b

File tree

1 file changed

+1
-18
lines changed

1 file changed

+1
-18
lines changed

src/histogram.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ impl Instant {
542542

543543
#[inline]
544544
pub fn elapsed_sec(&self) -> f64 {
545-
duration_to_seconds(self.elapsed())
545+
self.elapsed().as_secs_f64()
546546
}
547547
}
548548

@@ -881,13 +881,6 @@ pub fn exponential_buckets(start: f64, factor: f64, count: usize) -> Result<Vec<
881881
Ok(buckets)
882882
}
883883

884-
/// `duration_to_seconds` converts Duration to seconds.
885-
#[inline]
886-
pub fn duration_to_seconds(d: Duration) -> f64 {
887-
let nanos = f64::from(d.subsec_nanos()) / 1e9;
888-
d.as_secs() as f64 + nanos
889-
}
890-
891884
#[derive(Clone, Debug)]
892885
pub struct LocalHistogramCore {
893886
histogram: Histogram,
@@ -1363,16 +1356,6 @@ mod tests {
13631356
}
13641357
}
13651358

1366-
#[test]
1367-
fn test_duration_to_seconds() {
1368-
let tbls = vec![(1000, 1.0), (1100, 1.1), (100_111, 100.111)];
1369-
for (millis, seconds) in tbls {
1370-
let d = Duration::from_millis(millis);
1371-
let v = duration_to_seconds(d);
1372-
assert!((v - seconds).abs() < f64::EPSILON);
1373-
}
1374-
}
1375-
13761359
#[test]
13771360
fn test_histogram_vec_with_label_values() {
13781361
let vec = HistogramVec::new(

0 commit comments

Comments
 (0)