golang.org/x/tools/gopls@v0.15.3/internal/test/integration/bench/definition_test.go (about) 1 // Copyright 2023 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package bench 6 7 import ( 8 "testing" 9 ) 10 11 func BenchmarkDefinition(b *testing.B) { 12 tests := []struct { 13 repo string 14 file string 15 regexp string 16 }{ 17 {"istio", "pkg/config/model.go", `gogotypes\.(MarshalAny)`}, 18 {"google-cloud-go", "httpreplay/httpreplay.go", `proxy\.(ForRecording)`}, 19 {"kubernetes", "pkg/controller/lookup_cache.go", `hashutil\.(DeepHashObject)`}, 20 {"kuma", "api/generic/insights.go", `proto\.(Message)`}, 21 {"pkgsite", "internal/log/log.go", `derrors\.(Wrap)`}, 22 {"starlark", "starlark/eval.go", "prog.compiled.(Encode)"}, 23 {"tools", "internal/lsp/cache/check.go", `(snapshot)\) buildKey`}, 24 } 25 26 for _, test := range tests { 27 b.Run(test.repo, func(b *testing.B) { 28 env := getRepo(b, test.repo).sharedEnv(b) 29 env.OpenFile(test.file) 30 defer closeBuffer(b, env, test.file) 31 32 loc := env.RegexpSearch(test.file, test.regexp) 33 env.Await(env.DoneWithOpen()) 34 env.GoToDefinition(loc) // pre-warm the query, and open the target file 35 b.ResetTimer() 36 37 if stopAndRecord := startProfileIfSupported(b, env, qualifiedName(test.repo, "definition")); stopAndRecord != nil { 38 defer stopAndRecord() 39 } 40 41 for i := 0; i < b.N; i++ { 42 env.GoToDefinition(loc) // pre-warm the query 43 } 44 }) 45 } 46 }