MCPcopy
hub / github.com/tinylib/msgp / benchStringAsBytes

Function benchStringAsBytes

msgp/read_test.go:797–813  ·  view source on GitHub ↗
(size uint32, b *testing.B)

Source from the content-addressed store, hash-verified

795}
796
797func benchStringAsBytes(size uint32, b *testing.B) {
798 str := string(RandBytes(int(size)))
799 data := make([]byte, 0, len(str)+5)
800 data = AppendString(data, str)
801 rd := NewReader(NewEndlessReader(data, b))
802 b.SetBytes(int64(len(data)))
803 b.ReportAllocs()
804 b.ResetTimer()
805 var scratch []byte
806 var err error
807 for i := 0; i < b.N; i++ {
808 scratch, err = rd.ReadStringAsBytes(scratch)
809 if err != nil {
810 b.Fatal(err)
811 }
812 }
813}
814
815func BenchmarkRead16StringAsBytes(b *testing.B) {
816 benchStringAsBytes(16, b)

Callers 2

Calls 5

ReadStringAsBytesMethod · 0.95
RandBytesFunction · 0.85
AppendStringFunction · 0.85
NewReaderFunction · 0.85
NewEndlessReaderFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…