Format a difference with percentage and direction indicator.
(*, old_bytes: int, new_bytes: int)
| 116 | |
| 117 | |
| 118 | def format_diff(*, old_bytes: int, new_bytes: int) -> str: |
| 119 | """Format a difference with percentage and direction indicator.""" |
| 120 | diff = new_bytes - old_bytes |
| 121 | |
| 122 | if diff == 0: |
| 123 | return "-" |
| 124 | |
| 125 | sign = "+" if diff > 0 else "" |
| 126 | |
| 127 | if old_bytes == 0: |
| 128 | return f"{sign}{format_bytes(diff)} (new)" |
| 129 | |
| 130 | return f"{sign}{diff / old_bytes:.2%} ({format_bytes(abs(diff))})" |
| 131 | |
| 132 | |
| 133 | def format_outcome(*, old_bytes: int, new_bytes: int) -> str: |
no test coverage detected