2022-03-01 12:44:34 +00:00
|
|
|
package refs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
2023-06-12 22:33:53 +00:00
|
|
|
|
|
|
|
refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
|
2022-03-01 12:44:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkObjectIDSlice(b *testing.B) {
|
|
|
|
for _, size := range []int{0, 1, 50} {
|
|
|
|
b.Run(strconv.Itoa(size)+" elements", func(b *testing.B) {
|
|
|
|
benchmarkObjectIDSlice(b, size)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func benchmarkObjectIDSlice(b *testing.B, size int) {
|
2023-06-12 22:33:53 +00:00
|
|
|
ids := refstest.GenerateObjectIDs(false)
|
2022-03-01 12:44:34 +00:00
|
|
|
|
2023-06-12 22:33:53 +00:00
|
|
|
b.Run("marshal", func(b *testing.B) {
|
2022-03-01 12:44:34 +00:00
|
|
|
b.ReportAllocs()
|
|
|
|
for i := 0; i < b.N; i++ {
|
2023-06-12 22:33:53 +00:00
|
|
|
size := 0
|
|
|
|
for _, id := range ids {
|
|
|
|
size += proto.NestedStructureSize(9, id)
|
2022-03-01 12:44:34 +00:00
|
|
|
}
|
2023-06-12 22:33:53 +00:00
|
|
|
|
|
|
|
buf := make([]byte, size)
|
|
|
|
offset := 0
|
|
|
|
for _, id := range ids {
|
|
|
|
offset += proto.NestedStructureMarshal(9, buf[offset:], id)
|
2022-03-01 12:44:34 +00:00
|
|
|
}
|
2023-06-12 22:33:53 +00:00
|
|
|
|
|
|
|
if offset != len(buf) {
|
2022-03-01 12:44:34 +00:00
|
|
|
b.FailNow()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|