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.
26 "gerrit.o-ran-sc.org/r/ric-plt/sdlgo"
29 type singleBenchmark struct {
35 type multiBenchmark struct {
42 type setBenchmark struct {
48 func (bm singleBenchmark) String(oper string) string {
49 return fmt.Sprintf("op = %s key=%d value=%d", oper, bm.keySize, bm.valueSize)
52 func (bm multiBenchmark) String(oper string) string {
53 return fmt.Sprintf("op = %s keycnt=%d key=%d value=%d", oper, bm.keyCount, bm.keySize, bm.valueSize)
56 func (bm setBenchmark) String(oper string) string {
57 return fmt.Sprintf("op = %s, memberCount=%d", oper, bm.memberCount)
59 func BenchmarkSet(b *testing.B) {
60 benchmarks := []singleBenchmark{
64 {"d", 10, 1024 * 1024},
65 {"e", 10, 10 * 1024 * 1024},
69 {"h", 100, 64 * 1024},
70 {"i", 100, 1024 * 1024},
71 {"j", 100, 10 * 1024 * 1024},
74 for _, bm := range benchmarks {
75 b.Run(bm.String("set"), func(b *testing.B) {
76 key := strings.Repeat(bm.key, bm.keySize)
77 value := strings.Repeat("1", bm.valueSize)
78 sdl := sdlgo.NewSdlInstance("namespace", sdlgo.NewDatabase())
81 b.RunParallel(func(pb *testing.PB) {
83 err := sdl.Set(key, value)
93 func BenchmarkGet(b *testing.B) {
94 benchmarks := []singleBenchmark{
98 {"d", 10, 1024 * 1024},
99 {"e", 10, 10 * 1024 * 1024},
103 {"h", 100, 64 * 1024},
104 {"i", 100, 1024 * 1024},
105 {"j", 100, 10 * 1024 * 1024},
108 for _, bm := range benchmarks {
109 b.Run(bm.String("Get"), func(b *testing.B) {
110 key := strings.Repeat(bm.key, bm.keySize)
111 value := strings.Repeat("1", bm.valueSize)
112 sdl := sdlgo.NewSdlInstance("namespace", sdlgo.NewDatabase())
113 if err := sdl.Set(key, value); err != nil {
117 b.RunParallel(func(pb *testing.PB) {
119 _, err := sdl.Get([]string{key})
129 func BenchmarkMultiSet(b *testing.B) {
130 benchmarks := []multiBenchmark{
140 {"i", 1000, 100, 64},
141 {"j", 5000, 100, 64},
144 for _, bm := range benchmarks {
145 b.Run(bm.String("mset"), func(b *testing.B) {
146 sdl := sdlgo.NewSdlInstance("namespace", sdlgo.NewDatabase())
147 value := strings.Repeat("1", bm.valueSize)
148 keyVals := make([]string, 0)
149 for i := 0; i < bm.keyCount; i++ {
150 key := strings.Repeat(bm.keyBase+strconv.Itoa(i), bm.keySize)
151 keyVals = append(keyVals, key, value)
154 b.RunParallel(func(pb *testing.PB) {
156 err := sdl.Set(keyVals)
166 func BenchmarkMultiGet(b *testing.B) {
167 benchmarks := []multiBenchmark{
177 {"i", 1000, 100, 64},
178 {"j", 5000, 100, 64},
181 for _, bm := range benchmarks {
182 b.Run(bm.String("gset"), func(b *testing.B) {
183 sdl := sdlgo.NewSdlInstance("namespace", sdlgo.NewDatabase())
184 keyVals := make([]string, 0)
185 for i := 0; i < bm.keyCount; i++ {
186 key := strings.Repeat(bm.keyBase+strconv.Itoa(i), bm.keySize)
187 keyVals = append(keyVals, key)
190 b.RunParallel(func(pb *testing.PB) {
192 _, err := sdl.Get(keyVals)
202 func BenchmarkSetAddMember(b *testing.B) {
203 benchmarks := []setBenchmark{
210 for _, bm := range benchmarks {
211 b.Run(bm.String("AddMember"), func(b *testing.B) {
212 sdl := sdlgo.NewSdlInstance("namespace", sdlgo.NewDatabase())
213 members := make([]string, 0)
214 for i := 0; i < bm.memberCount; i++ {
215 member := bm.member + strconv.Itoa(i)
216 members = append(members, member)
219 b.RunParallel(func(pb *testing.PB) {
221 err := sdl.AddMember(bm.key, members)