-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecord_test.go
More file actions
113 lines (90 loc) · 1.96 KB
/
record_test.go
File metadata and controls
113 lines (90 loc) · 1.96 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package atomiccache
import (
"reflect"
"testing"
)
func TestRecordSimple(t *testing.T) {
for _, c := range []struct {
size int
in []byte
want []byte
}{
{10, []byte{0}, []byte{0}},
{10, []byte{0, 1, 2, 3, 4, 5}, []byte{0, 1, 2, 3, 4, 5}},
{1, []byte{0, 1, 2}, []byte{0}},
} {
record := NewRecord(c.size)
record.Set(c.in)
if !reflect.DeepEqual(record.Get(), c.want) {
t.Errorf("[%d] %v != %v", c.size, record.Get(), c.want)
}
}
}
func TestRecordFree(t *testing.T) {
size := 10
want := []byte{0, 1, 2}
record := NewRecord(size)
record.Set(want)
record.Free()
if !reflect.DeepEqual(record.Get(), []byte{}) {
t.Errorf("[%d] %v != %v", 10, record.Get(), want)
}
}
func benchmarkRecordNew(size int, b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
NewRecord(size)
}
}
func BenchmarkRecordNewSmall(b *testing.B) {
benchmarkRecordNew(512, b)
}
func BenchmarkRecordNewMedium(b *testing.B) {
benchmarkRecordNew(1024, b)
}
func BenchmarkRecordNewLarge(b *testing.B) {
benchmarkRecordNew(2048, b)
}
func benchmarkRecordSet(size int, b *testing.B) {
var data []byte
record := NewRecord(size)
for i := 0; i < size; i++ {
data = append(data, 1)
}
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
record.Set(data)
}
}
func BenchmarkRecordSetSmall(b *testing.B) {
benchmarkRecordSet(512, b)
}
func BenchmarkRecordSetMedium(b *testing.B) {
benchmarkRecordSet(1024, b)
}
func BenchmarkRecordSetLarge(b *testing.B) {
benchmarkRecordSet(2048, b)
}
func benchmarkRecordGet(size int, b *testing.B) {
var data []byte
record := NewRecord(size)
record.Set(data)
for i := 0; i < size; i++ {
data = append(data, 1)
}
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
record.Get()
}
}
func BenchmarkRecordGetSmall(b *testing.B) {
benchmarkRecordGet(512, b)
}
func BenchmarkRecordGetMedium(b *testing.B) {
benchmarkRecordGet(1024, b)
}
func BenchmarkRecordGetLarge(b *testing.B) {
benchmarkRecordGet(2048, b)
}