MCPcopy Create free account
hub / github.com/consistent-milk12/masstree / format_comparison

Function format_comparison

scripts/run_cpp_bench.py:289–313  ·  view source on GitHub ↗

Format a comparison row, returning (test, cpp, rust, ratio).

(
    test: str,
    cpp_mops: Optional[float],
    rust_mops: Optional[float],
    use_color: bool = True,
)

Source from the content-addressed store, hash-verified

287
288
289def 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
316def print_comparison_table(

Callers 1

print_comparison_tableFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected