blob: e18ad4e9aa68d70ebcff3ce5d67950a0f00225a9 (
plain)
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
|
// Copyright 2022 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"
"testing"
"golang.org/x/tools/gopls/internal/lsp/protocol"
)
// BenchmarkDidChange benchmarks modifications of a single file by making
// synthetic modifications in a comment. It controls pacing by waiting for the
// server to actually start processing the didChange notification before
// proceeding. Notably it does not wait for diagnostics to complete.
//
// Uses -workdir and -file to control where the edits occur.
func BenchmarkDidChange(b *testing.B) {
env := repos["tools"].sharedEnv(b)
const filename = "go/ast/astutil/util.go"
env.OpenFile(filename)
env.AfterChange()
// Insert the text we'll be modifying at the top of the file.
env.EditBuffer(filename, protocol.TextEdit{NewText: "// __REGTEST_PLACEHOLDER_0__\n"})
b.ResetTimer()
for i := 0; i < b.N; i++ {
env.EditBuffer(filename, 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("// __REGTEST_PLACEHOLDER_%d__\n", i+1),
})
env.Await(env.StartedChange())
}
}
|