| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package bench |
| 6 |
|
| 7 |
import ( |
| 8 |
"fmt" |
| 9 |
"sync/atomic" |
| 10 |
"testing" |
| 11 |
"time" |
| 12 |
|
| 13 |
"golang.org/x/tools/gopls/internal/protocol" |
| 14 |
) |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
func BenchmarkTyping(b *testing.B) { |
| 22 |
for _, test := range didChangeTests { |
| 23 |
b.Run(test.repo, func(b *testing.B) { |
| 24 |
env := getRepo(b, test.repo).sharedEnv(b) |
| 25 |
env.OpenFile(test.file) |
| 26 |
defer closeBuffer(b, env, test.file) |
| 27 |
|
| 28 |
|
| 29 |
env.EditBuffer(test.file, protocol.TextEdit{NewText: "// __TEST_PLACEHOLDER_0__\n"}) |
| 30 |
env.AfterChange() |
| 31 |
|
| 32 |
delays := []time.Duration{ |
| 33 |
10 * time.Millisecond, |
| 34 |
50 * time.Millisecond, |
| 35 |
150 * time.Millisecond, |
| 36 |
} |
| 37 |
|
| 38 |
for _, delay := range delays { |
| 39 |
b.Run(delay.String(), func(b *testing.B) { |
| 40 |
if stopAndRecord := startProfileIfSupported(b, env, qualifiedName(test.repo, "typing")); stopAndRecord != nil { |
| 41 |
defer stopAndRecord() |
| 42 |
} |
| 43 |
ticker := time.NewTicker(delay) |
| 44 |
for b.Loop() { |
| 45 |
edits := atomic.AddInt64(&editID, 1) |
| 46 |
env.EditBuffer(test.file, protocol.TextEdit{ |
| 47 |
Range: protocol.Range{ |
| 48 |
Start: protocol.Position{Line: 0, Character: 0}, |
| 49 |
End: protocol.Position{Line: 1, Character: 0}, |
| 50 |
}, |
| 51 |
|
| 52 |
NewText: fmt.Sprintf("// __TEST_PLACEHOLDER_%d__\n", edits), |
| 53 |
}) |
| 54 |
<-ticker.C |
| 55 |
} |
| 56 |
b.StopTimer() |
| 57 |
ticker.Stop() |
| 58 |
env.AfterChange() |
| 59 |
}) |
| 60 |
} |
| 61 |
}) |
| 62 |
} |
| 63 |
} |