-
Notifications
You must be signed in to change notification settings - Fork 1
test: fix BenchmarkNova clone setup #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -660,27 +660,30 @@ func withWorkingDir(t *testing.T, dir string) { | |
| t.Cleanup(func() { _ = os.Chdir(prev) }) | ||
| } | ||
|
|
||
| func CloneRepoToTestDir(b *testing.B, repoUrl string) *File { | ||
| func cloneRepoToBenchDir(b *testing.B, repoURL string) *File { | ||
| b.Helper() | ||
| d := newTestDir(b, "", "*") | ||
| defer os.Remove(d.Path) | ||
| d := newTestDir(b, "", "bench") | ||
| b.Cleanup(func() { _ = os.RemoveAll(d.Path) }) | ||
|
|
||
| cmd := exec.Command("git", "clone", "--depth=1", "--single-branch", repoUrl, ".") | ||
| cmd := exec.Command("git", "clone", "--depth=1", "--single-branch", repoURL, ".") | ||
| cmd.Dir = d.Path | ||
| out, err := cmd.CombinedOutput() | ||
| if err != nil { | ||
| b.Errorf("failed to clone repo: %s", out) | ||
| b.Fatalf("failed to clone repo: %s", out) | ||
| } | ||
|
|
||
| return d | ||
| } | ||
|
|
||
| func BenchmarkNova(b *testing.B) { | ||
| const repoURL = "https://github.com/openstack/nova.git" | ||
|
|
||
| b.StopTimer() | ||
| d := cloneRepoToBenchDir(b, repoURL) | ||
| fr := findReplace{find: RandomString(2), replace: RandomString(2)} | ||
| b.ResetTimer() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
After Useful? React with 👍 / 👎. |
||
|
|
||
| for n := 0; n < b.N; n++ { | ||
| b.StopTimer() | ||
| d := CloneRepoToTestDir(b, "git@github.com:openstack/nova.git") | ||
| fr := findReplace{find: RandomString(2), replace: RandomString(2)} | ||
| b.StartTimer() | ||
| fr.WalkDir(d) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the checkout is cloned only once outside the
b.Nloop, the firstWalkDirmutates that tree by rewriting contents and renaming paths; whenb.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 👍 / 👎.