my @col_widths;
my @top_row = (
'',
$display_as_rate ? 'Rate' : 's/iter',
map { $_->[0] } @vals
);
push @rows, \@top_row;
@col_widths = map { length( $_ ) } @top_row;
# Build the data rows
# We leave the last column in even though it never has any data. Perhaps
# it should go away. Also, perhaps a style for a single column of
# percentages might be nice.
for my $row_val ( @vals ) {
my @row;
# Column 0 = test name
push @row, $row_val->[0];
$col_widths[0] = length( $row_val->[0] )
if length( $row_val->[0] ) > $col_widths[0];
# Column 1 = performance
my $row_rate = $row_val->[7];
# We assume that we'll never get a 0 rate.
my $rate = $display_as_rate ? $row_rate : 1 / $row_rate;
# Only give a few decimal places before switching to sci. notation,
# since the results aren't usually that accurate anyway.
my $format =
$rate >= 100 ?
"%0.0f" :
$rate >= 10 ?
"%0.1f" :
$rate >= 1 ?
"%0.2f" :
$rate >= 0.1 ?
"%0.3f" :
"%0.2e";
$format .= "/s"
if $display_as_rate;
my $formatted_rate = sprintf( $format, $rate );
push @row, $formatted_rate;
$col_widths[1] = length( $formatted_rate )
if length( $formatted_rate ) > $col_widths[1];
# Columns 2..N = performance ratios
my $skip_rest = 0;
for ( my $col_num = 0 ; $col_num < @vals ; ++$col_num ) {
my $col_val = $vals[$col_num];
my $out;
if ( $skip_rest ) {
$out = '';
}
elsif ( $col_val->[0] eq $row_val->[0] ) {
$out = "--";
# $skip_rest = 1;
}
else {
my $col_rate = $col_val->[7];
$out = sprintf( "%.0f%%", 100*$row_rate/$col_rate - 100 );
}
push @row, $out;
$col_widths[$col_num+2] = length( $out )
if length( $out ) > $col_widths[$col_num+2];
# A little wierdness to set the first column width properly
$col_widths[$col_num+2] = length( $col_val->[0] )
if length( $col_val->[0] ) > $col_widths[$col_num+2];
}
push @rows, \@row;
}
return \@rows if $style eq "none";
# Equalize column widths in the chart as much as possible without
# exceeding 80 characters. This does not use or affect cols 0 or 1.
my @sorted_width_refs =
sort { $$a <=> $$b } map { \$_ } @col_widths[2..$#col_widths];
my $max_width = ${$sorted_width_refs[-1]};
my $total = @col_widths - 1 ;
for ( @col_widths ) { $total += $_ }
STRETCHER:
while ( $total < 80 ) {
my $min_width = ${$sorted_width_refs[0]};
last
if $min_width == $max_width;
for ( @sorted_width_refs ) {
last
if $$_ > $min_width;
++$$_;
++$total;
last STRETCHER
if $total >= 80;
=10= |