Format a comparison row, returning (test, cpp, rust, ratio).
(
test: str,
cpp_mops: Optional[float],
rust_mops: Optional[float],
use_color: bool = True,
)
| 287 | |
| 288 | |
| 289 | def format_comparison( |
| 290 | test: str, |
| 291 | cpp_mops: Optional[float], |
| 292 | rust_mops: Optional[float], |
| 293 | use_color: bool = True, |
| 294 | ) -> Tuple[str, str, str, str]: |
| 295 | """Format a comparison row, returning (test, cpp, rust, ratio).""" |
| 296 | cpp_str = f"{cpp_mops:.2f}" if cpp_mops is not None else "N/A" |
| 297 | rust_str = f"{rust_mops:.2f}" if rust_mops is not None else "N/A" |
| 298 | |
| 299 | if cpp_mops is not None and rust_mops is not None and cpp_mops > 0: |
| 300 | ratio = rust_mops / cpp_mops * 100 |
| 301 | ratio_str = f"{ratio:.0f}%" |
| 302 | |
| 303 | if use_color: |
| 304 | if ratio >= 100: |
| 305 | ratio_str = f"{GREEN}{BOLD}{ratio_str}{RESET}" |
| 306 | elif ratio >= 80: |
| 307 | ratio_str = f"{YELLOW}{ratio_str}{RESET}" |
| 308 | else: |
| 309 | ratio_str = f"{RED}{ratio_str}{RESET}" |
| 310 | else: |
| 311 | ratio_str = "N/A" |
| 312 | |
| 313 | return test, cpp_str, rust_str, ratio_str |
| 314 | |
| 315 | |
| 316 | def print_comparison_table( |
no outgoing calls
no test coverage detected