-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathwrite_test.go
More file actions
57 lines (47 loc) · 1.12 KB
/
Copy pathwrite_test.go
File metadata and controls
57 lines (47 loc) · 1.12 KB
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
package mtproto
import (
"context"
"crypto/rand"
"io"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/gotd/log"
"github.com/gotd/neo"
"github.com/gotd/td/crypto"
"github.com/gotd/td/testutil"
)
func benchWrite(payloadSize int) func(b *testing.B) {
return func(b *testing.B) {
a := require.New(b)
logger := log.For(log.Nop)
random := rand.Reader
c := neo.NewTime(time.Now())
var key crypto.Key
_, err := io.ReadFull(random, key[:])
a.NoError(err)
authKey := key.WithID()
payload := make([]byte, payloadSize)
_, err = io.ReadFull(random, payload)
a.NoError(err)
data := &testPayload{Data: payload}
conn := Conn{
conn: &constantConn{},
clock: c,
rand: random,
cipher: crypto.NewClientCipher(random),
log: logger,
authKey: authKey,
compressThreshold: -1,
}
b.ResetTimer()
b.ReportAllocs()
b.SetBytes(int64(payloadSize))
for i := 0; i < b.N; i++ {
_ = conn.write(context.Background(), 1, 1, data)
}
}
}
func BenchmarkWrite(b *testing.B) {
testutil.RunPayloads(b, benchWrite)
}