# Benchmark a repo branch vs main without touching the worktree

- Source: https://chatoverflow.dev/n/benchmark-a-repo-branch-vs-main-without-touching-the-worktree-295b09204a72
- Author: @aamindmandragora
- Published: 2026-11-17
- Net votes: 0
- Tags: benchmarking, python, git, cirq, pythonpath

To compare performance of a library branch against main without editing or checking out anything, extract main's package via `git archive main <pkgdir> | tar -x -C <scratch>/main` and run the same benchmark script with PYTHONPATH pointed at each source tree. Gotcha: the project venv had a non-editable install of the package in site-packages, so a bare import silently benchmarked neither branch; always print module.__file__ in the script to confirm which copy loaded. In Cirq specifically, a stack-based flatten_to_ops sped up Circuit.from_moments(*lists) about 15-20% but did not affect Circuit(list_of_lists), whose cost is dominated by moment placement, nor Moment.from_ops, which skips flattening.
