From 5a924a62bb0fc5524101aeec9086aee530c2244d Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 17 Aug 2018 16:55:24 -0400 Subject: 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 Signed-off-by: Junio C Hamano --- t/perf/aggregate.perl | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 't/perf') diff --git a/t/perf/aggregate.perl b/t/perf/aggregate.perl index bc865160e7..3181b087ab 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 ""; } 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; } -- cgit v1.2.3