Skip to content

Commit 1299c17

Browse files
committed
Add a %diff to compare command and some emoji
* currently the compare outputs the absolute diff with color coding * this isn't very helpful when trying to copy past into GH issue * just a proof of concept on how to add a %diff with emoji red or green circle * another way to add color is LateX syntax that is supported by Github but that becomes very verbose * can likely add emoji as an optional param Signed-off-by: Asim Mahmood <[email protected]>
1 parent e23766d commit 1299c17

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Diff for: osbenchmark/results_publisher.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -715,15 +715,23 @@ def _append_non_empty(self, lines, line):
715715
def _line(self, metric, baseline, contender, task, unit, treat_increase_as_improvement, formatter=lambda x: x):
716716
if baseline is not None and contender is not None:
717717
return [metric, str(task), formatter(baseline), formatter(contender),
718-
self._diff(baseline, contender, treat_increase_as_improvement, formatter), unit]
718+
*self._diff(baseline, contender, treat_increase_as_improvement, formatter), unit]
719719
else:
720720
return []
721721

722722
def _diff(self, baseline, contender, treat_increase_as_improvement, formatter=lambda x: x):
723723
def identity(x):
724724
return x
725725

726+
# Avoid division by zero
727+
if baseline == 0:
728+
percentage_diff = 0
729+
else:
730+
# Calculate percentage difference: ((new - old) / old) * 100
731+
percentage_diff = ((contender - baseline) / baseline) * 100
732+
percentage_diff = formatter(percentage_diff)
726733
diff = formatter(contender - baseline)
734+
727735
if self.plain:
728736
color_greater = identity
729737
color_smaller = identity
@@ -737,10 +745,11 @@ def identity(x):
737745
color_smaller = console.format.green
738746
color_neutral = console.format.neutral
739747

740-
if diff > 0:
741-
return color_greater("+%.5f" % diff)
742-
elif diff < 0:
743-
return color_smaller("%.5f" % diff)
748+
if percentage_diff > 5.0:
749+
return color_greater("+%.2f%%" % percentage_diff)+" :red_circle:",color_greater("+%.5f" % diff)
750+
elif percentage_diff < -5.0:
751+
return color_smaller("%.2f%%" % percentage_diff)+" :green_circle:",color_smaller("%.5f" % diff)
744752
else:
745753
# tabulate needs this to align all values correctly
746-
return color_neutral("%.5f" % diff)
754+
return color_neutral("%.2f%%" % percentage_diff),color_neutral("%.5f" % diff)
755+

0 commit comments

Comments
 (0)