Format a difference with percentage and direction indicator.
(*, old_bytes: int, new_bytes: int)
| 98 | |
| 99 | |
| 100 | def format_diff(*, old_bytes: int, new_bytes: int) -> str: |
| 101 | """Format a difference with percentage and direction indicator.""" |
| 102 | diff = new_bytes - old_bytes |
| 103 | |
| 104 | if diff == 0: |
| 105 | return "-" |
| 106 | |
| 107 | sign = "+" if diff > 0 else "" |
| 108 | |
| 109 | if old_bytes == 0: |
| 110 | return f"{sign}{format_bytes(diff)} (new)" |
| 111 | |
| 112 | return f"{sign}{diff / old_bytes:.2%} ({format_bytes(abs(diff))})" |
| 113 | |
| 114 | |
| 115 | def format_outcome(*, old_bytes: int, new_bytes: int) -> str: |
no test coverage detected