1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package bench
import (
"fmt"
"sync/atomic"
"testing"
"golang.org/x/tools/gopls/internal/protocol"
)
func BenchmarkCodeAction(b *testing.B) {
for _, test := range didChangeTests {
b.Run(test.repo, func(b *testing.B) {
env := getRepo(b, test.repo).sharedEnv(b)
env.OpenFile(test.file)
defer closeBuffer(b, env, test.file)
env.AfterChange()
env.CodeActionForFile(test.file, nil) // pre-warm
b.ResetTimer()
if stopAndRecord := startProfileIfSupported(b, env, qualifiedName(test.repo, "hover")); stopAndRecord != nil {
defer stopAndRecord()
}
for i := 0; i < b.N; i++ {
env.CodeActionForFile(test.file, nil)
}
})
}
}
func BenchmarkCodeActionFollowingEdit(b *testing.B) {
for _, test := range didChangeTests {
b.Run(test.repo, func(b *testing.B) {
env := getRepo(b, test.repo).sharedEnv(b)
env.OpenFile(test.file)
defer closeBuffer(b, env, test.file)
env.EditBuffer(test.file, protocol.TextEdit{NewText: "// __TEST_PLACEHOLDER_0__\n"})
env.AfterChange()
env.CodeActionForFile(test.file, nil) // pre-warm
b.ResetTimer()
if stopAndRecord := startProfileIfSupported(b, env, qualifiedName(test.repo, "hover")); stopAndRecord != nil {
defer stopAndRecord()
}
for i := 0; i < b.N; i++ {
edits := atomic.AddInt64(&editID, 1)
env.EditBuffer(test.file, protocol.TextEdit{
Range: protocol.Range{
Start: protocol.Position{Line: 0, Character: 0},
End: protocol.Position{Line: 1, Character: 0},
},
// Increment the placeholder text, to ensure cache misses.
NewText: fmt.Sprintf("// __TEST_PLACEHOLDER_%d__\n", edits),
})
env.CodeActionForFile(test.file, nil)
}
})
}
}
|