Skip to content

Commit

Permalink
Add BenchmarkEncodeSliceInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
marselester committed Dec 3, 2022
1 parent 3251188 commit 9d00c2c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,31 @@ func TestEncodeSliceInterface(t *testing.T) {
}
}

func BenchmarkEncodeSliceInterface(b *testing.B) {
val := []interface{}{"foo", "bar"}
sig := SignatureOf(val)
buf := &bytes.Buffer{}
fds := make([]int, 0)

b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
buf.Reset()

enc := newEncoder(buf, binary.LittleEndian, fds)
err := enc.Encode(val)
if err != nil {
b.Fatal(err)
}

dec := newDecoder(buf, binary.LittleEndian, enc.fds)
_, err = dec.Decode(sig)
if err != nil {
b.Fatal(err)
}
}
}

func TestEncodeSliceNamedInterface(t *testing.T) {
val := []empty{"foo", "bar"}
buf := new(bytes.Buffer)
Expand Down

0 comments on commit 9d00c2c

Please sign in to comment.