golang.org/x/tools/gopls@v0.15.3/internal/test/integration/bench/references_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 "testing" 8 9 func BenchmarkReferences(b *testing.B) { 10 tests := []struct { 11 repo string 12 file string 13 regexp string 14 }{ 15 {"google-cloud-go", "httpreplay/httpreplay.go", `func (NewRecorder)`}, 16 {"istio", "pkg/config/model.go", "type (Meta)"}, 17 {"kubernetes", "pkg/controller/lookup_cache.go", "type (objectWithMeta)"}, // TODO: choose an exported identifier 18 {"kuma", "pkg/events/interfaces.go", "type (Event)"}, 19 {"pkgsite", "internal/log/log.go", "func (Infof)"}, 20 {"starlark", "syntax/syntax.go", "type (Ident)"}, 21 {"tools", "internal/lsp/source/view.go", "type (Snapshot)"}, 22 } 23 24 for _, test := range tests { 25 b.Run(test.repo, func(b *testing.B) { 26 env := getRepo(b, test.repo).sharedEnv(b) 27 env.OpenFile(test.file) 28 defer closeBuffer(b, env, test.file) 29 30 loc := env.RegexpSearch(test.file, test.regexp) 31 env.AfterChange() 32 env.References(loc) // pre-warm the query 33 b.ResetTimer() 34 35 if stopAndRecord := startProfileIfSupported(b, env, qualifiedName(test.repo, "references")); stopAndRecord != nil { 36 defer stopAndRecord() 37 } 38 39 for i := 0; i < b.N; i++ { 40 env.References(loc) 41 } 42 }) 43 } 44 }