This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
bench.pl: improve single-field formatting
authorDavid Mitchell <davem@iabyn.com>
Mon, 1 Dec 2014 12:48:12 +0000 (12:48 +0000)
committerDavid Mitchell <davem@iabyn.com>
Mon, 1 Dec 2014 12:48:12 +0000 (12:48 +0000)
With a single field specified by --fields=foo, bench.pl uses a more
compact output format. Tidy this a bit: left-justify the test names,
and describe which field is being listed in the header.

Porting/bench.pl

index 7068a18..039997c 100755 (executable)
@@ -1055,6 +1055,7 @@ EOF
     my $one_field = defined $OPTS{fields} &&  keys(%{$OPTS{fields}}) == 1;
 
     if ($one_field) {
+        print "Results for field " . (keys(%{$OPTS{fields}}))[0] . ".\n";
 
         # The first column will now contain test names rather than
         # field names; Calculate the max width.
@@ -1115,8 +1116,12 @@ EOF
                 next;
             }
 
-            printf "%*s", $field_label_width,
-                        $one_field ? $test_name : $field;
+            if ($one_field) {
+                printf "%-*s", $field_label_width, $test_name;
+            }
+            else {
+                printf "%*s", $field_label_width, $field;
+            }
 
             for my $i (0..$#widths) {
                 my $res2 = $res1->{$perl_names[$i]};