2022-03-01 12:44:34 +00:00
|
|
|
package refs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
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) {
|
2022-03-01 12:50:09 +00:00
|
|
|
ids := make([]ObjectID, size)
|
2022-03-01 12:44:34 +00:00
|
|
|
for i := range ids {
|
|
|
|
ids[i].val = make([]byte, 32)
|
|
|
|
rand.Read(ids[i].val)
|
|
|
|
}
|
|
|
|
raw := ObjectIDListToGRPCMessage(ids)
|
|
|
|
|
|
|
|
b.Run("to grpc message", func(b *testing.B) {
|
|
|
|
b.ReportAllocs()
|
2024-09-04 12:44:59 +00:00
|
|
|
for range b.N {
|
2022-03-01 12:44:34 +00:00
|
|
|
raw := ObjectIDListToGRPCMessage(ids)
|
|
|
|
if len(raw) != len(ids) {
|
|
|
|
b.FailNow()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
b.Run("from grpc message", func(b *testing.B) {
|
|
|
|
b.ReportAllocs()
|
2024-09-04 12:44:59 +00:00
|
|
|
for range b.N {
|
2022-03-01 12:44:34 +00:00
|
|
|
ids, err := ObjectIDListFromGRPCMessage(raw)
|
|
|
|
if err != nil || len(raw) != len(ids) {
|
|
|
|
b.FailNow()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
b.Run("marshal", func(b *testing.B) {
|
|
|
|
b.ReportAllocs()
|
2024-09-04 12:44:59 +00:00
|
|
|
for range b.N {
|
2022-03-01 12:44:34 +00:00
|
|
|
buf := make([]byte, ObjectIDNestedListSize(1, ids))
|
2022-04-05 08:24:34 +00:00
|
|
|
n := ObjectIDNestedListMarshal(1, buf, ids)
|
|
|
|
if n != len(buf) {
|
2022-03-01 12:44:34 +00:00
|
|
|
b.FailNow()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|