| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package bench |
| 6 |
|
| 7 |
import ( |
| 8 |
"testing" |
| 9 |
|
| 10 |
"golang.org/x/tools/gopls/internal/protocol" |
| 11 |
"golang.org/x/tools/gopls/internal/protocol/command" |
| 12 |
. "golang.org/x/tools/gopls/internal/test/integration" |
| 13 |
"golang.org/x/tools/gopls/internal/test/integration/fake" |
| 14 |
) |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
func BenchmarkInitialWorkspaceLoad(b *testing.B) { |
| 24 |
repoNames := []string{ |
| 25 |
"google-cloud-go", |
| 26 |
"istio", |
| 27 |
"kubernetes", |
| 28 |
"kuma", |
| 29 |
"oracle", |
| 30 |
"pkgsite", |
| 31 |
"starlark", |
| 32 |
"tools", |
| 33 |
"hashiform", |
| 34 |
} |
| 35 |
for _, repoName := range repoNames { |
| 36 |
b.Run(repoName, func(b *testing.B) { |
| 37 |
repo := getRepo(b, repoName) |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
sharedEnv := repo.sharedEnv(b) |
| 42 |
b.ResetTimer() |
| 43 |
|
| 44 |
for b.Loop() { |
| 45 |
doIWL(b, sharedEnv.Sandbox.GOPATH(), repo, nil) |
| 46 |
} |
| 47 |
}) |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
func BenchmarkInitialWorkspaceLoadOpenFiles(b *testing.B) { |
| 58 |
for _, t := range didChangeTests { |
| 59 |
b.Run(t.repo, func(b *testing.B) { |
| 60 |
repo := getRepo(b, t.repo) |
| 61 |
sharedEnv := repo.sharedEnv(b) |
| 62 |
b.ResetTimer() |
| 63 |
|
| 64 |
for b.Loop() { |
| 65 |
doIWL(b, sharedEnv.Sandbox.GOPATH(), repo, []string{t.file}) |
| 66 |
} |
| 67 |
}) |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
func doIWL(b *testing.B, gopath string, repo *repo, openfiles []string) { |
| 72 |
|
| 73 |
|
| 74 |
b.StopTimer() |
| 75 |
config := fake.EditorConfig{Env: map[string]string{"GOPATH": gopath}} |
| 76 |
env := repo.newEnv(b, config, "iwl", true) |
| 77 |
defer env.Close() |
| 78 |
b.StartTimer() |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
env.Await(InitialWorkspaceLoad) |
| 83 |
|
| 84 |
for _, f := range openfiles { |
| 85 |
env.OpenFile(f) |
| 86 |
} |
| 87 |
|
| 88 |
env.AfterChange() |
| 89 |
|
| 90 |
if env.Editor.HasCommand(command.MemStats) { |
| 91 |
b.StopTimer() |
| 92 |
params := &protocol.ExecuteCommandParams{ |
| 93 |
Command: command.MemStats.String(), |
| 94 |
} |
| 95 |
var memstats command.MemStatsResult |
| 96 |
env.ExecuteCommand(params, &memstats) |
| 97 |
b.ReportMetric(float64(memstats.HeapAlloc), "alloc_bytes") |
| 98 |
b.ReportMetric(float64(memstats.HeapInUse), "in_use_bytes") |
| 99 |
b.ReportMetric(float64(memstats.TotalAlloc), "total_alloc_bytes") |
| 100 |
b.StartTimer() |
| 101 |
} |
| 102 |
} |