MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / main

Function main

benchmarks/run_benchmarks.py:478–539  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

476
477
478def main() -> None:
479 parser = argparse.ArgumentParser(description="TraceDecay vs Token-Savior benchmark")
480 parser.add_argument(
481 "--repos",
482 nargs="+",
483 choices=list(REPOS.keys()),
484 default=list(REPOS.keys()),
485 )
486 parser.add_argument("--skip-clone", action="store_true")
487 parser.add_argument("--skip-token-savior", action="store_true")
488 parser.add_argument("--skip-tracedecay", action="store_true")
489 args = parser.parse_args()
490
491 if not args.skip_token_savior and not have_token_savior():
492 log("token-savior not installed (`pip install token-savior`); skipping its column")
493 args.skip_token_savior = True
494 if not args.skip_tracedecay and shutil.which(TRACEDECAY_BIN) is None:
495 log(f"{TRACEDECAY_BIN} not on PATH; skipping its column")
496 args.skip_tracedecay = True
497 if args.skip_token_savior and args.skip_tracedecay:
498 log("Both tools unavailable; nothing to benchmark.")
499 sys.exit(1)
500
501 results: list[dict] = []
502 naive_sizes: dict[str, int] = {}
503
504 for name in args.repos:
505 try:
506 root = clone_repo(name, REPOS[name], skip_clone=args.skip_clone)
507 except (subprocess.CalledProcessError, FileNotFoundError) as exc:
508 detail = getattr(exc, "stderr", None) or str(exc)
509 log(f"SKIP {name}: clone failed -- {detail.strip()[:200]}")
510 continue
511
512 naive_sizes[name] = naive_source_size(str(root))
513 entry: dict = {"repo": name, "root": str(root)}
514 sample: list[str] | None = None
515
516 if not args.skip_token_savior:
517 ts_result, sample = benchmark_token_savior(name, root)
518 entry["token_savior"] = ts_result
519
520 if not args.skip_tracedecay:
521 if not sample:
522 sample = fallback_sample(root)
523 entry["tracedecay"] = benchmark_tracedecay(name, root, sample)
524
525 results.append(entry)
526
527 if not results:
528 log("No repos benchmarked, exiting.")
529 sys.exit(1)
530
531 RESULTS_DIR.mkdir(parents=True, exist_ok=True)
532 payload = {"results": results, "naive_source_size_bytes": naive_sizes}
533 RESULTS_JSON.write_text(json.dumps(payload, indent=2))
534 log(f"Results written to {RESULTS_JSON}")
535

Callers 1

run_benchmarks.pyFile · 0.70

Calls 9

have_token_saviorFunction · 0.85
clone_repoFunction · 0.85
naive_source_sizeFunction · 0.85
benchmark_token_saviorFunction · 0.85
fallback_sampleFunction · 0.85
benchmark_tracedecayFunction · 0.85
generate_reportFunction · 0.85
logFunction · 0.70
listFunction · 0.50

Tested by

no test coverage detected