github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/storage/segment/serialization_bench_test.go (about) 1 package segment 2 3 import ( 4 "bytes" 5 "fmt" 6 "math/big" 7 "math/rand" 8 "testing" 9 "time" 10 11 ptesting "github.com/pyroscope-io/pyroscope/pkg/testing" 12 ) 13 14 func serialize(s *Segment) []byte { 15 var buf bytes.Buffer 16 s.Serialize(&buf) 17 return buf.Bytes() 18 } 19 20 func BenchmarkSerialize(b *testing.B) { 21 for k := 10; k <= 1000000; k *= 10 { 22 s := New() 23 for i := 0; i < k; i++ { 24 s.Put(ptesting.SimpleTime(i*10), ptesting.SimpleTime(i*10+9), uint64(rand.Intn(100)), func(de int, t time.Time, r *big.Rat, a []Addon) {}) 25 } 26 b.ResetTimer() 27 b.Run(fmt.Sprintf("serialize %d", k), func(b *testing.B) { 28 for i := 0; i < b.N; i++ { 29 _ = serialize(s) 30 } 31 }) 32 } 33 }