Skip to content

Commit

Permalink
fix benchmarks, add few utils
Browse files Browse the repository at this point in the history
  • Loading branch information
manosriram committed Dec 20, 2023
1 parent d3c0c52 commit 34cdf93
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions benchmark/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func set(b *testing.B) {
func get(b *testing.B) {
for i := 0; i < 10000; i++ {
kv := &nimbusdb.KeyValuePair{
Key: []byte(fmt.Sprintf("%d", rand.Int())),
Key: []byte(utils.GetTestKey(i)),
Value: []byte("testvalue"),
}
_, err := db.Set(kv)
Expand All @@ -63,7 +63,7 @@ func get(b *testing.B) {

for i := 0; i < b.N; i++ {
kv := &nimbusdb.KeyValuePair{
Key: []byte(fmt.Sprintf("%d", rand.Int())),
Key: []byte(utils.GetTestKey(rand.Int())),
Value: []byte("testvalue"),
}
_, err := db.Get(kv.Key)
Expand Down
22 changes: 22 additions & 0 deletions utils/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,35 @@ import (
"encoding/binary"
"fmt"
"log"
"math/rand"
"os"
"path/filepath"
"strconv"
"strings"
"sync"
"time"
)

var (
lock = sync.Mutex{}
randStr = rand.New(rand.NewSource(time.Now().Unix()))
letters = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
)

func GetTestKey(i int) []byte {
return []byte(fmt.Sprintf("nimbusdb_test_key_%09d", i))
}

func RandomValue(n int) []byte {
b := make([]byte, n)
for i := range b {
lock.Lock()
b[i] = letters[randStr.Intn(len(letters))]
lock.Unlock()
}
return []byte("nimbusdb_test_value_" + string(b))
}

func TimeUntilUnixNano(tstamp int64) time.Duration {
return time.Until(time.Unix(0, tstamp))
}
Expand Down

0 comments on commit 34cdf93

Please sign in to comment.