diff --git a/lib/encoding/int_timing_test.go b/lib/encoding/int_timing_test.go index 1316ef514..12dad83a0 100644 --- a/lib/encoding/int_timing_test.go +++ b/lib/encoding/int_timing_test.go @@ -231,5 +231,57 @@ func benchmarkUnmarshalVarInt64s(b *testing.B, maxValue int64) { }) } +func BenchmarkMarshalVarUint64(b *testing.B) { + b.Run("small-ints", func(b *testing.B) { + benchmarkMarshalVarUint64(b, []uint64{1,2,3,4,5,67,127}) + }) + b.Run("big-ints", func(b *testing.B) { + benchmarkMarshalVarUint64(b, []uint64{12355,89832432, 8989843, 8989989, 883443, 9891233, 8232434342}) + }) +} + +func benchmarkMarshalVarUint64(b *testing.B, a []uint64) { + b.ReportAllocs() + b.SetBytes(int64(len(a))) + b.RunParallel(func(pb *testing.PB) { + var buf []byte + var sink uint64 + for pb.Next() { + buf = buf[:0] + for _, n := range a { + buf = MarshalVarUint64(buf, n) + } + sink += uint64(len(buf)) + } + Sink.Add(sink) + }) +} + +func BenchmarkMarshalVarInt64(b *testing.B) { + b.Run("small-ints", func(b *testing.B) { + benchmarkMarshalVarInt64(b, []int64{1,2,3,-4,5,-60,63}) + }) + b.Run("big-ints", func(b *testing.B) { + benchmarkMarshalVarInt64(b, []int64{12355,-89832432, 8989843, -8989989, 883443, -9891233, 8232434342}) + }) +} + +func benchmarkMarshalVarInt64(b *testing.B, a []int64) { + b.ReportAllocs() + b.SetBytes(int64(len(a))) + b.RunParallel(func(pb *testing.PB) { + var buf []byte + var sink uint64 + for pb.Next() { + buf = buf[:0] + for _, n := range a { + buf = MarshalVarInt64(buf, n) + } + sink += uint64(len(buf)) + } + Sink.Add(sink) + }) +} + var testMarshaledInt64Data = MarshalInt64(nil, 1234567890) var testMarshaledUint64Data = MarshalUint64(nil, 1234567890) diff --git a/lib/stringsutil/stringsutil_timing_test.go b/lib/stringsutil/stringsutil_timing_test.go index c2eddc454..498725d43 100644 --- a/lib/stringsutil/stringsutil_timing_test.go +++ b/lib/stringsutil/stringsutil_timing_test.go @@ -82,6 +82,7 @@ func benchmarkStringsToLower(b *testing.B, a []string) { var buf []byte var n uint64 for pb.Next() { + buf = buf[:0] for _, s := range a { sLower := strings.ToLower(s) buf = append(buf, sLower...)