-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes_test.go
More file actions
58 lines (53 loc) · 993 Bytes
/
types_test.go
File metadata and controls
58 lines (53 loc) · 993 Bytes
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
58
package cbytecache
import (
"testing"
)
func TestTypes(t *testing.T) {
t.Run("entry copy", func(t *testing.T) {
e := Entry{
Key: "test0",
Body: []byte("foobar"),
Expire: 15,
}
cpy := e.Copy()
assertString(t, e.Key, cpy.Key)
assertBytes(t, e.Body, cpy.Body)
})
}
type testq struct{}
func (q testq) Enqueue(x any) error {
e, ok := x.(Entry)
if !ok {
return nil
}
_, _, _ = e.Key, e.Body, e.Expire
return nil
}
func BenchmarkTypes(b *testing.B) {
b.Run("entry copy", func(b *testing.B) {
b.ReportAllocs()
e := Entry{
Key: "test0",
Body: []byte("foobar"),
Expire: 15,
}
for i := 0; i < b.N; i++ {
cpy := e.Copy()
assertString(b, e.Key, cpy.Key)
assertBytes(b, e.Body, cpy.Body)
}
})
b.Run("entry enqueue", func(b *testing.B) {
b.ReportAllocs()
e := Entry{
Key: "test0",
Body: []byte("foobar"),
Expire: 15,
}
var q testq
for i := 0; i < b.N; i++ {
cpy := e.Copy()
_ = q.Enqueue(cpy)
}
})
}