| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package bench |
| 5 |
|
| 6 |
import ( |
| 7 |
"fmt" |
| 8 |
"path" |
| 9 |
"regexp" |
| 10 |
"testing" |
| 11 |
|
| 12 |
. "golang.org/x/tools/gopls/internal/test/integration" |
| 13 |
) |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
func BenchmarkReload(b *testing.B) { |
| 20 |
type replace map[string]string |
| 21 |
tests := []struct { |
| 22 |
repo string |
| 23 |
file string |
| 24 |
|
| 25 |
|
| 26 |
replace replace |
| 27 |
}{ |
| 28 |
|
| 29 |
|
| 30 |
{"kubernetes", "pkg/util/hash/hash.go", replace{`"hash"`: `"hashx"`}}, |
| 31 |
{"kubernetes", "pkg/kubelet/kubelet.go", replace{ |
| 32 |
`"k8s.io/kubernetes/pkg/kubelet/config"`: `"k8s.io/kubernetes/pkg/kubelet/configx"`, |
| 33 |
}}, |
| 34 |
} |
| 35 |
|
| 36 |
for _, test := range tests { |
| 37 |
b.Run(fmt.Sprintf("%s/%s", test.repo, path.Base(test.file)), func(b *testing.B) { |
| 38 |
env := getRepo(b, test.repo).sharedEnv(b) |
| 39 |
|
| 40 |
env.OpenFile(test.file) |
| 41 |
defer closeBuffer(b, env, test.file) |
| 42 |
|
| 43 |
env.AfterChange() |
| 44 |
|
| 45 |
profileName := qualifiedName("reload", test.repo, path.Base(test.file)) |
| 46 |
if stopAndRecord := startProfileIfSupported(b, env, profileName); stopAndRecord != nil { |
| 47 |
defer stopAndRecord() |
| 48 |
} |
| 49 |
|
| 50 |
b.ResetTimer() |
| 51 |
for b.Loop() { |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
for k, v := range test.replace { |
| 56 |
env.RegexpReplace(test.file, regexp.QuoteMeta(k), v) |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
env.Await(Diagnostics(ForFile(test.file))) |
| 64 |
for k, v := range test.replace { |
| 65 |
env.RegexpReplace(test.file, regexp.QuoteMeta(v), k) |
| 66 |
} |
| 67 |
env.Await(NoDiagnostics(ForFile(test.file))) |
| 68 |
} |
| 69 |
}) |
| 70 |
} |
| 71 |
} |