2 Copyright (c) 2019 AT&T Intellectual Property.
3 Copyright (c) 2018-2019 Nokia.
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
19 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
20 * platform project (RICP).
31 "gerrit.o-ran-sc.org/r/ric-plt/sdlgo"
34 type singleBenchmark struct {
40 type multiBenchmark struct {
47 type setBenchmark struct {
53 func (bm singleBenchmark) String(oper string) string {
54 return fmt.Sprintf("op = %s key=%d value=%d", oper, bm.keySize, bm.valueSize)
57 func (bm multiBenchmark) String(oper string) string {
58 return fmt.Sprintf("op = %s keycnt=%d key=%d value=%d", oper, bm.keyCount, bm.keySize, bm.valueSize)
61 func (bm setBenchmark) String(oper string) string {
62 return fmt.Sprintf("op = %s, memberCount=%d", oper, bm.memberCount)
64 func BenchmarkSet(b *testing.B) {
65 benchmarks := []singleBenchmark{
69 {"d", 10, 1024 * 1024},
70 {"e", 10, 10 * 1024 * 1024},
74 {"h", 100, 64 * 1024},
75 {"i", 100, 1024 * 1024},
76 {"j", 100, 10 * 1024 * 1024},
79 for _, bm := range benchmarks {
80 b.Run(bm.String("set"), func(b *testing.B) {
81 key := strings.Repeat(bm.key, bm.keySize)
82 value := strings.Repeat("1", bm.valueSize)
83 sdl := sdlgo.NewSdlInstance("namespace", sdlgo.NewDatabase())
86 b.RunParallel(func(pb *testing.PB) {
88 err := sdl.Set(key, value)
98 func BenchmarkGet(b *testing.B) {
99 benchmarks := []singleBenchmark{
102 {"c", 10, 64 * 1024},
103 {"d", 10, 1024 * 1024},
104 {"e", 10, 10 * 1024 * 1024},
108 {"h", 100, 64 * 1024},
109 {"i", 100, 1024 * 1024},
110 {"j", 100, 10 * 1024 * 1024},
113 for _, bm := range benchmarks {
114 b.Run(bm.String("Get"), func(b *testing.B) {
115 key := strings.Repeat(bm.key, bm.keySize)
116 value := strings.Repeat("1", bm.valueSize)
117 sdl := sdlgo.NewSdlInstance("namespace", sdlgo.NewDatabase())
118 if err := sdl.Set(key, value); err != nil {
122 b.RunParallel(func(pb *testing.PB) {
124 _, err := sdl.Get([]string{key})
134 func BenchmarkMultiSet(b *testing.B) {
135 benchmarks := []multiBenchmark{
145 {"i", 1000, 100, 64},
146 {"j", 5000, 100, 64},
149 for _, bm := range benchmarks {
150 b.Run(bm.String("mset"), func(b *testing.B) {
151 sdl := sdlgo.NewSdlInstance("namespace", sdlgo.NewDatabase())
152 value := strings.Repeat("1", bm.valueSize)
153 keyVals := make([]string, 0)
154 for i := 0; i < bm.keyCount; i++ {
155 key := strings.Repeat(bm.keyBase+strconv.Itoa(i), bm.keySize)
156 keyVals = append(keyVals, key, value)
159 b.RunParallel(func(pb *testing.PB) {
161 err := sdl.Set(keyVals)
171 func BenchmarkMultiGet(b *testing.B) {
172 benchmarks := []multiBenchmark{
182 {"i", 1000, 100, 64},
183 {"j", 5000, 100, 64},
186 for _, bm := range benchmarks {
187 b.Run(bm.String("gset"), func(b *testing.B) {
188 sdl := sdlgo.NewSdlInstance("namespace", sdlgo.NewDatabase())
189 keyVals := make([]string, 0)
190 for i := 0; i < bm.keyCount; i++ {
191 key := strings.Repeat(bm.keyBase+strconv.Itoa(i), bm.keySize)
192 keyVals = append(keyVals, key)
195 b.RunParallel(func(pb *testing.PB) {
197 _, err := sdl.Get(keyVals)
207 func BenchmarkSetAddMember(b *testing.B) {
208 benchmarks := []setBenchmark{
215 for _, bm := range benchmarks {
216 b.Run(bm.String("AddMember"), func(b *testing.B) {
217 sdl := sdlgo.NewSdlInstance("namespace", sdlgo.NewDatabase())
218 members := make([]string, 0)
219 for i := 0; i < bm.memberCount; i++ {
220 member := bm.member + strconv.Itoa(i)
221 members = append(members, member)
224 b.RunParallel(func(pb *testing.PB) {
226 err := sdl.AddMember(bm.key, members)