line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Benchmark::Object; |
2
|
1
|
|
|
1
|
|
23427
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
1103
|
use Time::HiRes qw(gettimeofday); |
|
1
|
|
|
|
|
2224
|
|
|
1
|
|
|
|
|
5
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub start { |
9
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
10
|
0
|
|
|
|
|
|
my $self = {}; |
11
|
0
|
|
|
|
|
|
$self->{RECORD}->{PAUSECOUNT} = 0; |
12
|
0
|
|
|
|
|
|
$self->{RECORD}->{RESUMECOUNT} = 0; |
13
|
0
|
|
|
|
|
|
($self->{RECORD}->{START_SEC}, $self->{RECORD}->{START_MICROSEC}) = gettimeofday(); |
14
|
0
|
|
|
|
|
|
return bless $self, $class; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub stop { |
19
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
20
|
0
|
|
|
|
|
|
($self->{RECORD}->{END_SEC}, $self->{RECORD}->{END_MICROSEC}) = gettimeofday(); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub pause { |
24
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
25
|
0
|
|
|
|
|
|
my $pause_count = $self->{RECORD}->{PAUSECOUNT}++; |
26
|
0
|
|
|
|
|
|
($self->{RECORD}->{'PAUSE'.$pause_count}->{START_SEC}, $self->{RECORD}->{'PAUSE'.$pause_count}->{START_MICROSEC}) = gettimeofday(); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub resume { |
30
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
31
|
0
|
|
|
|
|
|
my $resume_count = $self->{RECORD}->{RESUMECOUNT}++; |
32
|
0
|
|
|
|
|
|
($self->{RECORD}->{'RESUME'.$resume_count}->{START_SEC}, $self->{RECORD}->{'RESUME'.$resume_count}->{START_MICROSEC}) = gettimeofday(); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _add_fields { |
36
|
0
|
|
|
0
|
|
|
my $self = shift; |
37
|
|
|
|
|
|
|
#Forcing to use stop function |
38
|
0
|
0
|
0
|
|
|
|
unless (defined($self->{RECORD}->{END_SEC}) || defined($self->{RECORD}->{END_MICROSEC})) { |
39
|
0
|
|
|
|
|
|
die "Must call stop function to stop bench-marking."; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
#Calculating Start and End Datetime in genaral format |
44
|
0
|
|
|
|
|
|
my @months = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); |
45
|
0
|
|
|
|
|
|
my ($sec, $min, $hour, $day, $month, $year) = (localtime($self->{RECORD}->{START_SEC}))[0,1,2,3,4,5]; |
46
|
0
|
|
|
|
|
|
$year = $year+1900; |
47
|
0
|
|
|
|
|
|
$hour =~ s/\b(\d)\b/0$1/; |
48
|
0
|
|
|
|
|
|
$min =~ s/\b(\d)\b/0$1/; |
49
|
0
|
|
|
|
|
|
$sec =~ s/\b(\d)\b/0$1/; |
50
|
0
|
|
|
|
|
|
$self->{RECORD}->{START_DATETIME} = qq($months[$month] $day $year $hour:$min:$sec); |
51
|
0
|
|
|
|
|
|
($sec, $min, $hour, $day, $month, $year) = (localtime($self->{RECORD}->{END_SEC}))[0,1,2,3,4,5]; |
52
|
0
|
|
|
|
|
|
$year = $year+1900; |
53
|
0
|
|
|
|
|
|
$hour =~ s/\b(\d)\b/0$1/; |
54
|
0
|
|
|
|
|
|
$min =~ s/\b(\d)\b/0$1/; |
55
|
0
|
|
|
|
|
|
$sec =~ s/\b(\d)\b/0$1/; |
56
|
0
|
|
|
|
|
|
$self->{RECORD}->{END_DATETIME} = qq($months[$month] $day $year $hour:$min:$sec); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my ($total_pause_microsecs); |
60
|
|
|
|
|
|
|
#if pause done in between |
61
|
0
|
0
|
|
|
|
|
if (defined($self->{RECORD}->{PAUSE0}->{START_SEC})) { |
62
|
|
|
|
|
|
|
#Initiating calcluation |
63
|
0
|
|
|
|
|
|
$total_pause_microsecs = (($self->{RECORD}->{"PAUSE0"}->{START_SEC} * 1000000) + $self->{RECORD}->{"PAUSE0"}->{START_MICROSEC}) - (($self->{RECORD}->{START_SEC} * 1000000) + $self->{RECORD}->{START_MICROSEC}); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
#In between calculation |
66
|
0
|
|
|
|
|
|
my $i; |
67
|
0
|
|
|
|
|
|
for($i = 0; $i < $self->{RECORD}->{RESUMECOUNT}; $i++) { |
68
|
0
|
0
|
0
|
|
|
|
if (defined($self->{RECORD}->{'RESUME'.$i}->{START_SEC}) && defined($self->{RECORD}->{'RESUME'.$i}->{START_MICROSEC}) && defined($self->{RECORD}->{'PAUSE'.($i+1)}->{START_SEC}) && defined($self->{RECORD}->{'PAUSE'.($i+1)}->{START_MICROSEC})) { |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$total_pause_microsecs += ((($self->{RECORD}->{'PAUSE'.($i+1)}->{START_SEC} * 1000000) + $self->{RECORD}->{'PAUSE'.($i+1)}->{START_MICROSEC}) - (($self->{RECORD}->{'RESUME'.$i}->{START_SEC} * 1000000) + $self->{RECORD}->{'RESUME'.$i}->{START_MICROSEC})); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
#Ending calculation |
74
|
0
|
0
|
0
|
|
|
|
if (defined($self->{RECORD}->{'RESUME'.($i-1)}->{START_SEC}) && defined($self->{RECORD}->{'RESUME'.($i-1)}->{START_MICROSEC})) { |
75
|
0
|
|
|
|
|
|
$total_pause_microsecs += ((($self->{RECORD}->{END_SEC} * 1000000) + $self->{RECORD}->{END_MICROSEC}) - (($self->{RECORD}->{'RESUME'.($i-1)}->{START_SEC} * 1000000) + $self->{RECORD}->{'RESUME'.($i-1)}->{START_MICROSEC})); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} else { |
78
|
|
|
|
|
|
|
#If no pause in between |
79
|
0
|
|
|
|
|
|
$total_pause_microsecs = ($self->{RECORD}->{END_SEC} * 1000000 + $self->{RECORD}->{END_MICROSEC} - $self->{RECORD}->{START_SEC} * 1000000 + $self->{RECORD}->{START_MICROSEC}); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
#Total consumed seconds and microseconds |
83
|
0
|
|
|
|
|
|
$self->{RECORD}->{TAKEN_SEC} = sprintf("%d", ($total_pause_microsecs) / 1000000); |
84
|
0
|
|
|
|
|
|
$self->{RECORD}->{TAKEN_MICROSEC} = ($total_pause_microsecs) % 1000000; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
#Print benchmark in tablur form |
88
|
|
|
|
|
|
|
sub print_benchmark { |
89
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
90
|
0
|
|
|
|
|
|
_add_fields($self); |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
print qq(Start Datetime: $self->{RECORD}->{START_DATETIME}\n); |
93
|
0
|
|
|
|
|
|
print qq(End Datetime: $self->{RECORD}->{END_DATETIME}\n); |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
printf("%-20s%20s%20s%25s\n", "Iteration", "Second", "Microsecond", "Total in Microseconds"); |
96
|
0
|
|
|
|
|
|
printf("===========================================================================================\n"); |
97
|
0
|
|
|
|
|
|
printf("%-20s%20d%20d%25e\n", "START", $self->{RECORD}->{START_SEC}, $self->{RECORD}->{START_MICROSEC}, ($self->{RECORD}->{START_SEC} * 1000000 + $self->{RECORD}->{START_MICROSEC})); |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
my $bigger = ($self->{RECORD}->{RESUMECOUNT} > $self->{RECORD}->{PAUSECOUNT})? $self->{RECORD}->{RESUMECOUNT}: $self->{RECORD}->{PAUSECOUNT}; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
for(my $i = 0; $i < $bigger; $i++) { |
102
|
0
|
0
|
0
|
|
|
|
if (defined($self->{RECORD}->{'PAUSE'.$i}->{START_SEC}) && defined($self->{RECORD}->{'PAUSE'.$i}->{START_MICROSEC})) { |
103
|
0
|
|
|
|
|
|
printf("%-20s%20d%20d%25e\n", "PAUSE$i", $self->{RECORD}->{'PAUSE'.$i}->{START_SEC}, $self->{RECORD}->{'PAUSE'.$i}->{START_MICROSEC}, ($self->{RECORD}->{'PAUSE'.$i}->{START_SEC} * 1000000 + $self->{RECORD}->{'PAUSE'.$i}->{START_MICROSEC})); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
0
|
0
|
0
|
|
|
|
if (defined($self->{RECORD}->{'RESUME'.$i}->{START_SEC}) && defined($self->{RECORD}->{'RESUME'.$i}->{START_MICROSEC})) { |
107
|
0
|
|
|
|
|
|
printf("%-20s%20d%20d%25e\n", "RESUME$i", $self->{RECORD}->{'RESUME'.$i}->{START_SEC}, $self->{RECORD}->{'RESUME'.$i}->{START_MICROSEC}, ($self->{RECORD}->{'RESUME'.$i}->{START_SEC} * 1000000 + $self->{RECORD}->{'RESUME'.$i}->{START_MICROSEC})); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
printf("%-20s%20d%20d%25e\n", "END", $self->{RECORD}->{END_SEC}, $self->{RECORD}->{END_MICROSEC}, ($self->{RECORD}->{END_SEC} * 1000000 + $self->{RECORD}->{END_MICROSEC})); |
112
|
0
|
|
|
|
|
|
printf("===========================================================================================\n"); |
113
|
0
|
|
|
|
|
|
print qq(Total time taken: $self->{RECORD}->{TAKEN_SEC} seconds ); |
114
|
0
|
|
|
|
|
|
print qq($self->{RECORD}->{TAKEN_MICROSEC} microseconds\n); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
#Return data structure of benchmark |
118
|
|
|
|
|
|
|
sub get_benchmark { |
119
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
120
|
0
|
|
|
|
|
|
_add_fields($self); |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
return $self->{RECORD}; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |