forked from rurban/perl-compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_benchmark.pl
executable file
·53 lines (41 loc) · 1.2 KB
/
parse_benchmark.pl
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
#!/usr/bin/perl
my %type_times;
my $last;
# default values
my ( $start, $stop ) = ( 'preinit', 'preinit1' );
my $total = 0;
my @args = @ARGV;
$start = shift @args if @args;
$stop = shift @args if @args;
while (<STDIN>) {
my ( $time, $type ) = parse();
if ( $type eq $start ) {
$last = $time;
next;
}
last if $type eq $stop;
next unless $last;
next unless length $type;
my $delta = $time - $last;
$total += $delta;
$type_times{$type} ||= {};
$type_times{$type}->{start} ||= $time;
$type_times{$type}->{total} += $delta;
$type_times{$type}->{counter}++;
$last = $time;
}
delete $type_times{'START'};
printf "# Parse from '%s' to '%s' - %d usec\n", $start, $stop, ( $last - $type_times{$start}->{start} ) / 1_000;
foreach my $type ( sort { $type_times{$a}->{total} <=> $type_times{$b}->{total} } keys %type_times ) {
printf(
"%15s = %8d usec - %4d hits - %02.2f %%\n",
$type,
int( $type_times{$type}->{total} / 1_000 ),
$type_times{$type}->{counter},
$total ? $type_times{$type}->{total} / $total * 100 : 0,
);
}
sub parse {
m/^--USECONDS (\d+)\s+==\s+(.+)\n/ or return;
return ( "$1", "$2" );
}