golang.org/x/tools/gopls@v0.15.3/internal/test/integration/bench/rename_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  	"fmt"
     9  	"testing"
    10  )
    11  
    12  func BenchmarkRename(b *testing.B) {
    13  	tests := []struct {
    14  		repo     string
    15  		file     string
    16  		regexp   string
    17  		baseName string
    18  	}{
    19  		{"google-cloud-go", "httpreplay/httpreplay.go", `func (NewRecorder)`, "NewRecorder"},
    20  		{"istio", "pkg/config/model.go", `(Namespace) string`, "Namespace"},
    21  		{"kubernetes", "pkg/controller/lookup_cache.go", `hashutil\.(DeepHashObject)`, "DeepHashObject"},
    22  		{"kuma", "pkg/events/interfaces.go", `Delete`, "Delete"},
    23  		{"pkgsite", "internal/log/log.go", `func (Infof)`, "Infof"},
    24  		{"starlark", "starlark/eval.go", `Program\) (Filename)`, "Filename"},
    25  		{"tools", "internal/lsp/cache/snapshot.go", `meta \*(metadataGraph)`, "metadataGraph"},
    26  	}
    27  
    28  	for _, test := range tests {
    29  		names := 0 // bench function may execute multiple times
    30  		b.Run(test.repo, func(b *testing.B) {
    31  			env := getRepo(b, test.repo).sharedEnv(b)
    32  			env.OpenFile(test.file)
    33  			loc := env.RegexpSearch(test.file, test.regexp)
    34  			env.Await(env.DoneWithOpen())
    35  			env.Rename(loc, test.baseName+"X") // pre-warm the query
    36  			b.ResetTimer()
    37  
    38  			if stopAndRecord := startProfileIfSupported(b, env, qualifiedName(test.repo, "rename")); stopAndRecord != nil {
    39  				defer stopAndRecord()
    40  			}
    41  
    42  			for i := 0; i < b.N; i++ {
    43  				names++
    44  				newName := fmt.Sprintf("%s%d", test.baseName, names)
    45  				env.Rename(loc, newName)
    46  			}
    47  		})
    48  	}
    49  }