Skip to content

Commit b08ea1d

Browse files
Add a basic histograph for the data
1 parent 90c1073 commit b08ea1d

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

third_party/cli_bench/cli_bench.pl

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
###############################################################################
1717
###############################################################################
1818

19-
my $num = 50;
20-
my $ignore = 1;
19+
my $num = 50;
20+
my $ignore = 1;
21+
my $details = 1;
2122

2223
my $ok = GetOptions(
2324
'num=i' => \$num,
2425
'ignore=i' => \$ignore,
26+
'details!' => \$details,
2527
);
2628

2729

@@ -59,6 +61,11 @@
5961

6062
my $avg = int(average(@res));
6163

64+
if ($details) {
65+
show_details(@res);
66+
print "\n";
67+
}
68+
6269
print "Ran '$cmd' $num times with average completion time of $avg ms\n";
6370

6471
if ($exit != 0) {
@@ -68,6 +75,37 @@
6875
###############################################################################
6976
###############################################################################
7077

78+
sub show_details {
79+
my @res = @_;
80+
81+
my $x = {};
82+
my $max = 0;
83+
84+
# Build a hash of all the times:count
85+
foreach my $time (@res) {
86+
$x->{$time}++;
87+
88+
if ($x->{$time} > $max) {
89+
$max = $x->{$time};
90+
}
91+
}
92+
93+
my $target_width = 100; # How wide we want the bar + text
94+
my $total = scalar(@res);
95+
my $scale = ($target_width - 15) / $max;
96+
97+
print "\n";
98+
99+
# Print out a basic histogram of the times
100+
foreach my $time (sort(keys %$x)) {
101+
my $count = $x->{$time};
102+
my $percent = sprintf("%0.1f", ($count / $total) * 100);
103+
104+
my $bar = "%" x ($count * $scale);
105+
print "$time ms: $bar ($percent%)\n";
106+
}
107+
}
108+
71109
sub average {
72110
my $ret = 0;
73111

0 commit comments

Comments
 (0)