stario/circle_benchmark_test.go

45 lines
862 B
Go
Raw Permalink Normal View History

package stario
import (
"io"
"testing"
)
func BenchmarkStarBufferByteRoundTrip(b *testing.B) {
buf, err := NewStarBuffer(4096)
if err != nil {
b.Fatal(err)
}
b.ReportAllocs()
b.SetBytes(1)
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := buf.putByte('a'); err != nil {
b.Fatal(err)
}
if _, err := buf.getByte(); err != nil {
b.Fatal(err)
}
}
}
func BenchmarkStarBufferChunkRoundTrip(b *testing.B) {
buf, err := NewStarBuffer(8192)
if err != nil {
b.Fatal(err)
}
payload := []byte("hello world b612 hello world b612 b612 b612 b612 b612 b612")
scratch := make([]byte, len(payload))
b.ReportAllocs()
b.SetBytes(int64(len(payload)))
b.ResetTimer()
for i := 0; i < b.N; i++ {
if _, err := buf.Write(payload); err != nil {
b.Fatal(err)
}
if _, err := io.ReadFull(buf, scratch); err != nil {
b.Fatal(err)
}
}
}