t/perf: factor out percent calculations
This will let us reuse the code when we add new values to aggregate besides times. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
968e77a5f8
commit
5a924a62bb
@ -19,21 +19,24 @@ sub get_times {
|
|||||||
return ($rt, $4, $5);
|
return ($rt, $4, $5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub relative_change {
|
||||||
|
my ($r, $firstr) = @_;
|
||||||
|
if ($firstr > 0) {
|
||||||
|
return sprintf "%+.1f%%", 100.0*($r-$firstr)/$firstr;
|
||||||
|
} elsif ($r == 0) {
|
||||||
|
return "=";
|
||||||
|
} else {
|
||||||
|
return "+inf";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub format_times {
|
sub format_times {
|
||||||
my ($r, $u, $s, $firstr) = @_;
|
my ($r, $u, $s, $firstr) = @_;
|
||||||
if (!defined $r) {
|
if (!defined $r) {
|
||||||
return "<missing>";
|
return "<missing>";
|
||||||
}
|
}
|
||||||
my $out = sprintf "%.2f(%.2f+%.2f)", $r, $u, $s;
|
my $out = sprintf "%.2f(%.2f+%.2f)", $r, $u, $s;
|
||||||
if (defined $firstr) {
|
$out .= ' ' . relative_change($r, $firstr) if defined $firstr;
|
||||||
if ($firstr > 0) {
|
|
||||||
$out .= sprintf " %+.1f%%", 100.0*($r-$firstr)/$firstr;
|
|
||||||
} elsif ($r == 0) {
|
|
||||||
$out .= " =";
|
|
||||||
} else {
|
|
||||||
$out .= " +inf";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user