summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-08-17 20:55:24 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-08-20 21:04:47 (GMT)
commit5a924a62bb0fc5524101aeec9086aee530c2244d (patch)
treef21972dfbfd4931658bd115c691d60efce578e69 /t
parent968e77a5f87c1a50983323f15296a6dda53a1098 (diff)
downloadgit-5a924a62bb0fc5524101aeec9086aee530c2244d.zip
git-5a924a62bb0fc5524101aeec9086aee530c2244d.tar.gz
git-5a924a62bb0fc5524101aeec9086aee530c2244d.tar.bz2
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>
Diffstat (limited to 't')
-rwxr-xr-xt/perf/aggregate.perl21
1 files changed, 12 insertions, 9 deletions
diff --git a/t/perf/aggregate.perl b/t/perf/aggregate.perl
index bc86516..3181b08 100755
--- a/t/perf/aggregate.perl
+++ b/t/perf/aggregate.perl
@@ -19,21 +19,24 @@ sub get_times {
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 {
my ($r, $u, $s, $firstr) = @_;
if (!defined $r) {
return "<missing>";
}
my $out = sprintf "%.2f(%.2f+%.2f)", $r, $u, $s;
- if (defined $firstr) {
- if ($firstr > 0) {
- $out .= sprintf " %+.1f%%", 100.0*($r-$firstr)/$firstr;
- } elsif ($r == 0) {
- $out .= " =";
- } else {
- $out .= " +inf";
- }
- }
+ $out .= ' ' . relative_change($r, $firstr) if defined $firstr;
return $out;
}