golang.org/x/tools/gopls@v0.15.3/internal/test/integration/bench/hover_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 BenchmarkHover(b *testing.B) {
    12  	tests := []struct {
    13  		repo   string
    14  		file   string
    15  		regexp string
    16  	}{
    17  		{"google-cloud-go", "httpreplay/httpreplay.go", `proxy\.(ForRecording)`},
    18  		{"istio", "pkg/config/model.go", `gogotypes\.(MarshalAny)`},
    19  		{"kubernetes", "pkg/apis/core/types.go", "type (Pod)"},
    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.AfterChange()
    34  
    35  			env.Hover(loc) // pre-warm the query
    36  			b.ResetTimer()
    37  
    38  			if stopAndRecord := startProfileIfSupported(b, env, qualifiedName(test.repo, "hover")); stopAndRecord != nil {
    39  				defer stopAndRecord()
    40  			}
    41  
    42  			for i := 0; i < b.N; i++ {
    43  				env.Hover(loc) // pre-warm the query
    44  			}
    45  		})
    46  	}
    47  }