Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.

[tstate] inline byte to string conversions #174

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
nits
Signed-off-by: Sam Batschelet <[email protected]>
  • Loading branch information
hexfusion committed May 15, 2023
commit 06ebd7f58d55c6d464c3a07b0f150fb4718fb12f
17 changes: 9 additions & 8 deletions tstate/tstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func benchmarkFetchAndSetScope(b *testing.B, size int) {
db := NewTestDB()
ctx := context.TODO()

keys, vals := initializeSet(size)
keys, vals := initializeSet(require, size)
for i, key := range keys {
err := db.Insert(ctx, key, vals[i])
require.NoError(err, "Error during insert.")
Expand All @@ -376,7 +376,7 @@ func benchmarkInsert(b *testing.B, size int) {
ts := New(size)
ctx := context.TODO()

keys, vals := initializeSet(size)
keys, vals := initializeSet(require, size)

storage := map[string][]byte{}
for i, key := range keys {
Expand All @@ -401,7 +401,7 @@ func benchmarkGetValue(b *testing.B, size int) {
ts := New(size)
ctx := context.TODO()

keys, vals := initializeSet(size)
keys, vals := initializeSet(require, size)

storage := map[string][]byte{}
for i, key := range keys {
Expand All @@ -421,20 +421,21 @@ func benchmarkGetValue(b *testing.B, size int) {
b.StopTimer()
}

func initializeSet(size int) ([][]byte, [][]byte) {
func initializeSet(r *require.Assertions, size int) ([][]byte, [][]byte) {
keys := [][]byte{}
vals := [][]byte{}

for i := 0; i <= size; i++ {
keys = append(keys, randomBytes(33))
vals = append(vals, randomBytes(8))
keys = append(keys, randomBytes(r, 65))
vals = append(vals, randomBytes(r, 8))
}

return keys, vals
}

func randomBytes(size int) []byte {
func randomBytes(r *require.Assertions, size int) []byte {
bytes := make([]byte, size)
rand.Read(bytes)
_, err := rand.Read(bytes)
r.NoError(err)
return bytes
}