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 func (bm singleBenchmark) String(oper string) string {
43 return fmt.Sprintf("op = %s key=%d value=%d", oper, bm.keySize, bm.valueSize)
46 func (bm multiBenchmark) String(oper string) string {
47 return fmt.Sprintf("op = %s keycnt=%d key=%d value=%d", oper, bm.keyCount, bm.keySize, bm.valueSize)
49 func BenchmarkSet(b *testing.B) {
50 benchmarks := []singleBenchmark{
54 {"d", 10, 1024 * 1024},
55 {"e", 10, 10 * 1024 * 1024},
59 {"h", 100, 64 * 1024},
60 {"i", 100, 1024 * 1024},
61 {"j", 100, 10 * 1024 * 1024},
64 for _, bm := range benchmarks {
65 b.Run(bm.String("set"), func(b *testing.B) {
66 key := strings.Repeat(bm.key, bm.keySize)
67 value := strings.Repeat("1", bm.valueSize)
68 sdl := sdlgo.NewSdlInstance("namespace", sdlgo.NewDatabase())
71 b.RunParallel(func(pb *testing.PB) {
73 err := sdl.Set(key, value)
83 func BenchmarkGet(b *testing.B) {
84 benchmarks := []singleBenchmark{
88 {"d", 10, 1024 * 1024},
89 {"e", 10, 10 * 1024 * 1024},
93 {"h", 100, 64 * 1024},
94 {"i", 100, 1024 * 1024},
95 {"j", 100, 10 * 1024 * 1024},
98 for _, bm := range benchmarks {
99 b.Run(bm.String("Get"), func(b *testing.B) {
100 key := strings.Repeat(bm.key, bm.keySize)
101 value := strings.Repeat("1", bm.valueSize)
102 sdl := sdlgo.NewSdlInstance("namespace", sdlgo.NewDatabase())
103 if err := sdl.Set(key, value); err != nil {
107 b.RunParallel(func(pb *testing.PB) {
109 _, err := sdl.Get([]string{key})
119 func BenchmarkMultiSet(b *testing.B) {
120 benchmarks := []multiBenchmark{
130 {"i", 1000, 100, 64},
131 {"j", 5000, 100, 64},
134 for _, bm := range benchmarks {
135 b.Run(bm.String("mset"), func(b *testing.B) {
136 sdl := sdlgo.NewSdlInstance("namespace", sdlgo.NewDatabase())
137 value := strings.Repeat("1", bm.valueSize)
138 keyVals := make([]string, 0)
139 for i := 0; i < bm.keyCount; i++ {
140 key := strings.Repeat(bm.keyBase+strconv.Itoa(i), bm.keySize)
141 keyVals = append(keyVals, key, value)
144 b.RunParallel(func(pb *testing.PB) {
146 err := sdl.Set(keyVals)
156 func BenchmarkMultiGet(b *testing.B) {
157 benchmarks := []multiBenchmark{
167 {"i", 1000, 100, 64},
168 {"j", 5000, 100, 64},
171 for _, bm := range benchmarks {
172 b.Run(bm.String("gset"), func(b *testing.B) {
173 sdl := sdlgo.NewSdlInstance("namespace", sdlgo.NewDatabase())
174 keyVals := make([]string, 0)
175 for i := 0; i < bm.keyCount; i++ {
176 key := strings.Repeat(bm.keyBase+strconv.Itoa(i), bm.keySize)
177 keyVals = append(keyVals, key)
180 b.RunParallel(func(pb *testing.PB) {
182 _, err := sdl.Get(keyVals)