test: fix BenchmarkNova clone setup#83
Conversation
Clone nova once over HTTPS, use b.Cleanup for teardown, and measure only WalkDir in the benchmark loop. Fixes dolph#16
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 69164dea8f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| b.StopTimer() | ||
| d := cloneRepoToBenchDir(b, repoURL) | ||
| fr := findReplace{find: RandomString(2), replace: RandomString(2)} | ||
| b.ResetTimer() |
There was a problem hiding this comment.
Restart the benchmark timer before walking
After b.StopTimer(), b.ResetTimer() only clears counters; the Go testing.B.ResetTimer docs state it does not affect whether the timer is running. As a result, every fr.WalkDir(d) call runs while the benchmark timer is still stopped, so go test -bench reports invalid near-zero timings. Call b.StartTimer() before the loop, or avoid stopping the timer and just reset it after setup.
Useful? React with 👍 / 👎.
| const repoURL = "https://github.com/openstack/nova.git" | ||
|
|
||
| b.StopTimer() | ||
| d := cloneRepoToBenchDir(b, repoURL) |
There was a problem hiding this comment.
Recreate the checkout for each benchmark iteration
Because the checkout is cloned only once outside the b.N loop, the first WalkDir mutates that tree by rewriting contents and renaming paths; when b.N > 1, later iterations walk an already-transformed repository and no longer measure the same find/replace workload. This amortizes a single real replacement run across many mostly no-op walks, so the benchmark result is misleading even after the timer is restarted.
Useful? React with 👍 / 👎.
Fixes #16
Made with Cursor