Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/counters/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ use std::{
time::Duration,
};

#[cfg(feature = "profiler")]
use web_time::Instant;

/// A timer.
#[derive(Copy, Clone, Debug, Default)]
pub struct Timer {
time: Duration,
#[allow(dead_code)] // The field isn’t used if the `profiler` feature isn’t enabled.
start: Option<std::time::Instant>,
#[cfg(feature = "profiler")]
start: Option<Instant>,
}

impl Timer {
/// Creates a new timer initialized to zero and not started.
pub fn new() -> Self {
Timer {
time: Duration::from_secs(0),
#[cfg(feature = "profiler")]
start: None,
}
}
Expand All @@ -30,7 +34,7 @@ impl Timer {
#[cfg(feature = "profiler")]
{
self.time = Duration::from_secs(0);
self.start = Some(web_time::Instant::now());
self.start = Some(Instant::now());
}
}

Expand All @@ -39,7 +43,7 @@ impl Timer {
#[cfg(feature = "profiler")]
{
if let Some(start) = self.start {
self.time += web_time::Instant::now().duration_since(start);
self.time += Instant::now().duration_since(start);
}
self.start = None;
}
Expand All @@ -49,7 +53,7 @@ impl Timer {
pub fn resume(&mut self) {
#[cfg(feature = "profiler")]
{
self.start = Some(web_time::Instant::now());
self.start = Some(Instant::now());
}
}

Expand Down