Files

41 lines
896 B
Go
Raw Permalink Normal View History

package notify
import (
"context"
"testing"
)
type discardRecordWriteStream struct{ *recordWriteCaptureStream }
func (s *discardRecordWriteStream) Write(p []byte) (int, error) { return len(p), nil }
func BenchmarkRecordWriteFlush64(b *testing.B) {
s := &discardRecordWriteStream{newRecordWriteCaptureStream()}
rs, err := WrapStreamAsRecord(s, RecordOpenOptions{})
if err != nil {
b.Fatal(err)
}
r := rs.(*recordStream)
b.Cleanup(func() { _ = r.Close() })
payload := make([]byte, 1024)
ctx := context.Background()
b.SetBytes(64 * int64(len(payload)))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
var last uint64
for j := 0; j < 64; j++ {
last, err = r.WriteRecord(ctx, payload)
if err != nil {
b.Fatal(err)
}
}
if err := r.Flush(ctx); err != nil {
b.Fatal(err)
}
if err := r.handleAckFrame(last); err != nil {
b.Fatal(err)
}
}
}