()
| 344 | |
| 345 | |
| 346 | def main() -> None: |
| 347 | args = parse_args() |
| 348 | use_color = not args.no_color and sys.stdout.isatty() |
| 349 | use_mimalloc = not args.no_mimalloc |
| 350 | |
| 351 | script_dir = Path(__file__).parent |
| 352 | project_dir = script_dir.parent |
| 353 | mttest_path = project_dir / "reference" / "build" / "mttest" |
| 354 | |
| 355 | run_cpp = not args.rust_only |
| 356 | |
| 357 | # Validate C++ binary exists |
| 358 | if run_cpp and not mttest_path.exists(): |
| 359 | print(f"Error: C++ mttest binary not found at {mttest_path}", file=sys.stderr) |
| 360 | print(f"Build it with: cd {project_dir / 'reference'} && make", file=sys.stderr) |
| 361 | sys.exit(1) |
| 362 | |
| 363 | # Header |
| 364 | mode = "C++ vs Rust" if args.compare else ("Rust" if args.rust_only else "C++") |
| 365 | pin_str = ", pinned" if args.pin else "" |
| 366 | # alloc_str only applies to Rust benchmarks (C++ allocator is baked into the binary) |
| 367 | show_rust = args.compare or args.rust_only |
| 368 | alloc_str = ", Rust system alloc" if not use_mimalloc and show_rust else "" |
| 369 | print( |
| 370 | f"{mode} Masstree mttest - {args.threads} threads, {args.duration}s{pin_str}{alloc_str}" |
| 371 | ) |
| 372 | |
| 373 | if args.compare: |
| 374 | # Comparison mode: run both and show table |
| 375 | results: List[Tuple[str, Optional[float], Optional[float]]] = [] |
| 376 | for i, test in enumerate(args.tests): |
| 377 | cpp_ops = run_cpp_benchmark( |
| 378 | mttest_path, |
| 379 | args.threads, |
| 380 | args.duration, |
| 381 | test, |
| 382 | args.pin, |
| 383 | args.quiet, |
| 384 | args.verbose, |
| 385 | ) |
| 386 | rust_ops = run_rust_benchmark( |
| 387 | project_dir, |
| 388 | args.threads, |
| 389 | args.duration, |
| 390 | test, |
| 391 | args.pin, |
| 392 | args.quiet, |
| 393 | args.verbose, |
| 394 | use_mimalloc, |
| 395 | ) |
| 396 | results.append((test, cpp_ops, rust_ops)) |
| 397 | # Gap between tests for thermal/system state normalization |
| 398 | if i < len(args.tests) - 1: |
| 399 | time.sleep(2) |
| 400 | |
| 401 | print_comparison_table(results, args.markdown, use_color) |
| 402 | |
| 403 | elif args.rust_only: |
no test coverage detected