Skip to content

Commit b857f3d

Browse files
committed
vlan_test: add benchmarks for VLAN.{M,Unm}arshalBinary
1 parent 4076b97 commit b857f3d

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

vlan_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,42 @@ func TestVLANUnmarshalBinary(t *testing.T) {
125125
}
126126
}
127127
}
128+
129+
// Benchmarks for VLAN.MarshalBinary
130+
131+
func BenchmarkVLANMarshalBinary(b *testing.B) {
132+
v := &VLAN{
133+
Priority: PriorityBackground,
134+
ID: 10,
135+
}
136+
137+
b.ResetTimer()
138+
b.ReportAllocs()
139+
for i := 0; i < b.N; i++ {
140+
if _, err := v.MarshalBinary(); err != nil {
141+
b.Fatal(err)
142+
}
143+
}
144+
}
145+
146+
// Benchmarks for VLAN.UnmarshalBinary
147+
148+
func BenchmarkVLANUnmarshalBinary(b *testing.B) {
149+
v := &VLAN{
150+
Priority: PriorityBestEffort,
151+
ID: 20,
152+
}
153+
154+
vb, err := v.MarshalBinary()
155+
if err != nil {
156+
b.Fatal(err)
157+
}
158+
159+
b.ResetTimer()
160+
b.ReportAllocs()
161+
for i := 0; i < b.N; i++ {
162+
if err := v.UnmarshalBinary(vb); err != nil {
163+
b.Fatal(err)
164+
}
165+
}
166+
}

0 commit comments

Comments
 (0)