-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuildTimer.pm
122 lines (87 loc) · 1.65 KB
/
BuildTimer.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package Timer;
use strict;
use Time::HiRes qw( time );
sub new
{
my $class = shift;
my $self = {};
bless $self, $class;
$self->Reset();
return $self;
}
sub Reset
{
my $self = shift;
$self->{ startTime } = time();
}
sub Elapsed
{
my $self = shift;
return time() - $self->{ startTime };
}
sub GetComponents
{
my $self = shift;
my $time = shift || $self->Elapsed();
my $hours = int( $time / ( 60 * 60 ) );
$time -= $hours * ( 60 * 60 );
my $minutes = int( $time / 60 );
$time -= $minutes * 60;
return ( $hours, $minutes, $time );
}
sub AsString
{
my $self = shift;
my $time = shift;
return sprintf( "%02d:%02d:%05.2f", $self->GetComponents( $time ) );
}
sub AsHighPrecisionString
{
my $self = shift;
my $time = shift;
return sprintf( "%02d:%02d:%09.6f", $self->GetComponents( $time ) );
}
1;
package Accumulator;
use strict;
use Time::HiRes qw( time );
sub new
{
my $class = shift;
my $self = {};
$self->{ value } = 0;
bless $self, $class;
return $self;
}
sub AsString
{
my $self = shift;
my $timer = Timer->new();
return $timer->AsString( $self->{ value } );
}
sub AsHighPrecisionString
{
my $self = shift;
my $timer = Timer->new();
return $timer->AsHighPrecisionString( $self->{ value } );
}
1;
package ScopeTimer;
use strict;
use Time::HiRes qw( time );
sub new
{
my $class = shift;
my $accumulatorRef = shift;
my $self = {};
$self->{ timer } = Timer->new();
$self->{ accumulatorRef } = $accumulatorRef;
bless $self, $class;
return $self;
}
sub DESTROY
{
my $self = shift;
${ $self->{ accumulatorRef } }->{ value } += $self->{ timer }->Elapsed();
}
1;