Skip to content

Commit fa093b2

Browse files
committed
gopls/internal/regtest/bench: add benchmarks for codeactions
Add missing benchmarks for codeactions. For golang/go#61508 Change-Id: I260fdae1c70c2e2291b7469cb7240d3d68cf1ded Reviewed-on: https://go-review.googlesource.com/c/tools/+/512495 Run-TryBot: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Alan Donovan <[email protected]> gopls-CI: kokoro <[email protected]>
1 parent d75c387 commit fa093b2

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
"sync/atomic"
10+
"testing"
11+
12+
"golang.org/x/tools/gopls/internal/lsp/protocol"
13+
)
14+
15+
func BenchmarkCodeAction(b *testing.B) {
16+
for _, test := range didChangeTests {
17+
b.Run(test.repo, func(b *testing.B) {
18+
env := getRepo(b, test.repo).sharedEnv(b)
19+
env.OpenFile(test.file)
20+
defer closeBuffer(b, env, test.file)
21+
env.AfterChange()
22+
23+
env.CodeAction(test.file, nil) // pre-warm
24+
25+
b.ResetTimer()
26+
27+
if stopAndRecord := startProfileIfSupported(b, env, qualifiedName(test.repo, "hover")); stopAndRecord != nil {
28+
defer stopAndRecord()
29+
}
30+
31+
for i := 0; i < b.N; i++ {
32+
env.CodeAction(test.file, nil)
33+
}
34+
})
35+
}
36+
}
37+
38+
func BenchmarkCodeActionFollowingEdit(b *testing.B) {
39+
for _, test := range didChangeTests {
40+
b.Run(test.repo, func(b *testing.B) {
41+
env := getRepo(b, test.repo).sharedEnv(b)
42+
env.OpenFile(test.file)
43+
defer closeBuffer(b, env, test.file)
44+
env.EditBuffer(test.file, protocol.TextEdit{NewText: "// __REGTEST_PLACEHOLDER_0__\n"})
45+
env.AfterChange()
46+
47+
env.CodeAction(test.file, nil) // pre-warm
48+
49+
b.ResetTimer()
50+
51+
if stopAndRecord := startProfileIfSupported(b, env, qualifiedName(test.repo, "hover")); stopAndRecord != nil {
52+
defer stopAndRecord()
53+
}
54+
55+
for i := 0; i < b.N; i++ {
56+
edits := atomic.AddInt64(&editID, 1)
57+
env.EditBuffer(test.file, protocol.TextEdit{
58+
Range: protocol.Range{
59+
Start: protocol.Position{Line: 0, Character: 0},
60+
End: protocol.Position{Line: 1, Character: 0},
61+
},
62+
// Increment the placeholder text, to ensure cache misses.
63+
NewText: fmt.Sprintf("// __REGTEST_PLACEHOLDER_%d__\n", edits),
64+
})
65+
env.CodeAction(test.file, nil)
66+
}
67+
})
68+
}
69+
}

0 commit comments

Comments
 (0)