@@ -3,19 +3,23 @@ use std::{
3
3
time:: Duration ,
4
4
} ;
5
5
6
+ #[ cfg( feature = "profiler" ) ]
7
+ use web_time:: Instant ;
8
+
6
9
/// A timer.
7
10
#[ derive( Copy , Clone , Debug , Default ) ]
8
11
pub struct Timer {
9
12
time : Duration ,
10
- #[ allow ( dead_code ) ] // The field isn’t used if the `profiler` feature isn’t enabled.
11
- start : Option < std :: time :: Instant > ,
13
+ #[ cfg ( feature = "profiler" ) ]
14
+ start : Option < Instant > ,
12
15
}
13
16
14
17
impl Timer {
15
18
/// Creates a new timer initialized to zero and not started.
16
19
pub fn new ( ) -> Self {
17
20
Timer {
18
21
time : Duration :: from_secs ( 0 ) ,
22
+ #[ cfg( feature = "profiler" ) ]
19
23
start : None ,
20
24
}
21
25
}
@@ -30,7 +34,7 @@ impl Timer {
30
34
#[ cfg( feature = "profiler" ) ]
31
35
{
32
36
self . time = Duration :: from_secs ( 0 ) ;
33
- self . start = Some ( web_time :: Instant :: now ( ) ) ;
37
+ self . start = Some ( Instant :: now ( ) ) ;
34
38
}
35
39
}
36
40
@@ -39,7 +43,7 @@ impl Timer {
39
43
#[ cfg( feature = "profiler" ) ]
40
44
{
41
45
if let Some ( start) = self . start {
42
- self . time += web_time :: Instant :: now ( ) . duration_since ( start) ;
46
+ self . time += Instant :: now ( ) . duration_since ( start) ;
43
47
}
44
48
self . start = None ;
45
49
}
@@ -49,7 +53,7 @@ impl Timer {
49
53
pub fn resume ( & mut self ) {
50
54
#[ cfg( feature = "profiler" ) ]
51
55
{
52
- self . start = Some ( web_time :: Instant :: now ( ) ) ;
56
+ self . start = Some ( Instant :: now ( ) ) ;
53
57
}
54
58
}
55
59
0 commit comments