github.com/TrueCloudLab/frostfs-api-go/v2@v2.0.0-20230228134343-196241c4e79a/refs/bench_test.go (about) 1 package refs 2 3 import ( 4 "math/rand" 5 "strconv" 6 "testing" 7 ) 8 9 func BenchmarkObjectIDSlice(b *testing.B) { 10 for _, size := range []int{0, 1, 50} { 11 b.Run(strconv.Itoa(size)+" elements", func(b *testing.B) { 12 benchmarkObjectIDSlice(b, size) 13 }) 14 } 15 } 16 17 func benchmarkObjectIDSlice(b *testing.B, size int) { 18 ids := make([]ObjectID, size) 19 for i := range ids { 20 ids[i].val = make([]byte, 32) 21 rand.Read(ids[i].val) 22 } 23 raw := ObjectIDListToGRPCMessage(ids) 24 25 b.Run("to grpc message", func(b *testing.B) { 26 b.ReportAllocs() 27 for i := 0; i < b.N; i++ { 28 raw := ObjectIDListToGRPCMessage(ids) 29 if len(raw) != len(ids) { 30 b.FailNow() 31 } 32 } 33 }) 34 b.Run("from grpc message", func(b *testing.B) { 35 b.ReportAllocs() 36 for i := 0; i < b.N; i++ { 37 ids, err := ObjectIDListFromGRPCMessage(raw) 38 if err != nil || len(raw) != len(ids) { 39 b.FailNow() 40 } 41 } 42 }) 43 b.Run("marshal", func(b *testing.B) { 44 b.ReportAllocs() 45 for i := 0; i < b.N; i++ { 46 buf := make([]byte, ObjectIDNestedListSize(1, ids)) 47 n := ObjectIDNestedListMarshal(1, buf, ids) 48 if n != len(buf) { 49 b.FailNow() 50 } 51 } 52 }) 53 }