mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
script for averaging results of running 'time' multiple times.
This commit is contained in:
parent
c298ecb1f1
commit
584e016083
1 changed files with 57 additions and 0 deletions
57
linux/scripts/times.pl
Executable file
57
linux/scripts/times.pl
Executable file
|
@ -0,0 +1,57 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
# Taking the output of time on stdin, sum all of the entries and print
|
||||
# out averages.
|
||||
|
||||
use strict;
|
||||
|
||||
#my %nSeen;
|
||||
my %nSecs;
|
||||
my $nDiscard = 0;
|
||||
|
||||
use constant PATS => ("real", "sys", "user");
|
||||
|
||||
map { $nSecs{$_} = [];} PATS;
|
||||
|
||||
my $parm = shift( @ARGV );
|
||||
if ( $parm eq "--discard" ) {
|
||||
$nDiscard = shift( @ARGV );
|
||||
} elsif ( defined $parm ) {
|
||||
print STDERR "usage: $0 [--discard num_high_and_low] < output_from_time\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
while ( <> ) {
|
||||
chomp;
|
||||
foreach my $pat (PATS) {
|
||||
tryOne( $pat, $_ );
|
||||
}
|
||||
}
|
||||
|
||||
print "results:\n";
|
||||
foreach my $pat (PATS) {
|
||||
my $ref = $nSecs{$pat};
|
||||
my @locList = sort { $a <=> $b; } @$ref;
|
||||
|
||||
# discard first and last from sorted list
|
||||
splice @locList, 0, $nDiscard;
|
||||
splice @locList, -$nDiscard;
|
||||
|
||||
my $count = @locList;
|
||||
if ( $count > 0 ) {
|
||||
my $sum;
|
||||
map { $sum += $_ } @locList;
|
||||
printf "$pat: average for $count runs: %.3f\n", $sum/$count;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub tryOne($$) {
|
||||
my ( $pat, $str ) = @_;
|
||||
|
||||
if ( $str =~ m|^$pat\s+(\d+)m(\d+\.\d+)s| ) {
|
||||
push @{$nSecs{$pat}}, ($1*60) + $2;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue