File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright 2020 The go-language-server 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 jsonrpc2
6
+
7
+ import (
8
+ "bytes"
9
+ "context"
10
+ "io/ioutil"
11
+ "testing"
12
+ )
13
+
14
+ const payload = `Content-Length: 265
15
+
16
+ {
17
+ "jsonrpc": "2.0",
18
+ "id": 1,
19
+ "method": "textDocument/didOpen",
20
+ "params": {
21
+ textDocument: {
22
+ "uri": "file:///path/to/basic.go",
23
+ "languageId": "go",
24
+ "version": 10,
25
+ "text": "package main
26
+
27
+ import \"fmt\"
28
+
29
+ func main() {
30
+ fmt.Print(\"test\")
31
+ }
32
+ "
33
+ }
34
+ }
35
+ }`
36
+
37
+ func BenchmarkSteam_Read (b * testing.B ) {
38
+ var in bytes.Buffer
39
+
40
+ b .ReportAllocs ()
41
+ b .ResetTimer ()
42
+ for i := 0 ; i < b .N ; i ++ {
43
+ in .Write ([]byte (payload ))
44
+ stream := NewStream (& in , ioutil .Discard )
45
+ _ , _ = stream .Read (context .Background ())
46
+ in .Reset ()
47
+ }
48
+ b .SetBytes (int64 (len (payload )))
49
+ }
50
+
51
+ func BenchmarkSteam_Write (b * testing.B ) {
52
+ b .ReportAllocs ()
53
+ b .ResetTimer ()
54
+ for i := 0 ; i < b .N ; i ++ {
55
+ stream := NewStream (nil , ioutil .Discard )
56
+ _ = stream .Write (context .Background (), []byte (payload ))
57
+ }
58
+ b .SetBytes (int64 (len (payload )))
59
+ }
You can’t perform that action at this time.
0 commit comments