line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright Infomation |
2
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
3
|
|
|
|
|
|
|
# Author : Dr. Ahmed Amin Elsheshtawy, Ph.D. |
4
|
|
|
|
|
|
|
# Website: https://github.com/mewsoft/Nile, http://www.mewsoft.com |
5
|
|
|
|
|
|
|
# Email : mewsoft@cpan.org, support@mewsoft.com |
6
|
|
|
|
|
|
|
# Copyrights (c) 2014-2015 Mewsoft Corp. All rights reserved. |
7
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
8
|
|
|
|
|
|
|
package Nile::Timer; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.55'; |
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:MEWSOFT'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=pod |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=encoding utf8 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Nile::Timer - Timer to clock operations. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# start the timer |
24
|
|
|
|
|
|
|
$app->timer->start; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# do some operations... |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# get time elapsed since start called |
29
|
|
|
|
|
|
|
say $app->timer->lap; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# do some other operations... |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# get time elapsed since last lap called |
34
|
|
|
|
|
|
|
say $app->timer->lap; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# get another timer object, timer automatically starts |
37
|
|
|
|
|
|
|
my $timer = $app->timer->new; |
38
|
|
|
|
|
|
|
say $timer->lap; |
39
|
|
|
|
|
|
|
#... |
40
|
|
|
|
|
|
|
say $timer->lap; |
41
|
|
|
|
|
|
|
#... |
42
|
|
|
|
|
|
|
say $timer->total; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# get total time elapsed since start |
45
|
|
|
|
|
|
|
say $app->timer->total; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 DESCRIPTION |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Nile::Timer - Timer to clock operations. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
1
|
|
4
|
use Nile::Base; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
54
|
1
|
|
|
1
|
|
5603
|
use Time::HiRes qw(gettimeofday tv_interval); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
11
|
|
55
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
56
|
|
|
|
|
|
|
sub BUILD { |
57
|
0
|
|
|
0
|
0
|
|
my ($self, $args) = @_; |
58
|
0
|
|
|
|
|
|
$self->start; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
61
|
|
|
|
|
|
|
=head2 start() |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# start the timer from now |
64
|
|
|
|
|
|
|
$app->timer->start; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Starts the timer. Timer starts by default when the application is started. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub start { |
71
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
72
|
0
|
|
|
|
|
|
my $now = [gettimeofday()]; |
73
|
0
|
|
|
|
|
|
$self->start_time($now); |
74
|
0
|
|
|
|
|
|
$self->lap_start_time($now); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
77
|
|
|
|
|
|
|
=head2 lap() |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
say $app->timer->lap; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Returns the time period since the last lap or from the start if not called before. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub lap { |
86
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
87
|
0
|
|
|
|
|
|
Time::HiRes::usleep 10000; |
88
|
0
|
|
|
|
|
|
my $now = [gettimeofday()]; |
89
|
0
|
|
|
|
|
|
my $lap = tv_interval($self->lap_start_time, $now); |
90
|
0
|
|
|
|
|
|
$self->lap_start_time([gettimeofday()]); |
91
|
0
|
|
|
|
|
|
return sprintf("%0f", $lap); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
94
|
|
|
|
|
|
|
=head2 total() |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# get total time since start called |
97
|
|
|
|
|
|
|
say $app->timer->total; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Returns the total time since the last start. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub total { |
104
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
105
|
0
|
|
|
|
|
|
my $now = [gettimeofday()]; |
106
|
0
|
|
|
|
|
|
my $lap = tv_interval($self->start_time, $now); |
107
|
0
|
|
|
|
|
|
return sprintf("%0f", $lap); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
110
|
|
|
|
|
|
|
=head2 start_time() |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
say $app->timer->start_time; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Returns the last start time. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
has 'start_time' => ( |
119
|
|
|
|
|
|
|
is => 'rw', |
120
|
|
|
|
|
|
|
); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 lap_start_time() |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
say $app->timer->lap_start_time; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Returns the last lap start time. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
has 'lap_start_time' => ( |
132
|
|
|
|
|
|
|
is => 'rw', |
133
|
|
|
|
|
|
|
); |
134
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
135
|
|
|
|
|
|
|
=head2 time() |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
say $app->timer->time; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Returns the current time. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub time { |
144
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
145
|
0
|
|
|
|
|
|
return [gettimeofday()]; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=pod |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 Bugs |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This project is available on github at L<https://github.com/mewsoft/Nile>. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 HOMEPAGE |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Please visit the project's homepage at L<https://metacpan.org/release/Nile>. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 SOURCE |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Source repository is at L<https://github.com/mewsoft/Nile>. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 SEE ALSO |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
See L<Nile> for details about the complete framework. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 AUTHOR |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Ahmed Amin Elsheshtawy, اØÙ
د اÙ
Ù٠اÙششتاÙÙ <mewsoft@cpan.org> |
170
|
|
|
|
|
|
|
Website: http://www.mewsoft.com |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Copyright (C) 2014-2015 by Dr. Ahmed Amin Elsheshtawy اØÙ
د اÙ
Ù٠اÙششتاÙÙ mewsoft@cpan.org, support@mewsoft.com, |
175
|
|
|
|
|
|
|
L<https://github.com/mewsoft/Nile>, L<http://www.mewsoft.com> |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
1; |