Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vpranckaitis committed Jan 19, 2021
1 parent 4fcbf54 commit 59887f4
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/x/serialize/decoder_fast_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ var samples = []string{

// BenchmarkTagValueFromEncodedTagsFast-12 11756650 110 ns/op
func BenchmarkTagValueFromEncodedTagsFast(b *testing.B) {
testData, err := prepareData(b)
require.NoError(b, err)
testData := prepareData(b)

b.ResetTimer()
for i := range testData {
Expand All @@ -72,16 +71,12 @@ func BenchmarkTagValueFromEncodedTagsFast(b *testing.B) {
}
}

func prepareData(b *testing.B) ([]encodedTagsWithTagName, error) {
func prepareData(b *testing.B) []encodedTagsWithTagName {
encodedTags, err := base64.StdEncoding.DecodeString(samples[0])
if err != nil {
return nil, err
}

require.NoError(b, err)
// Extracting tag names. Each sample has the same set of tag names, so using any of them
tagNames, err := decodeTagNames(encodedTags)
if err != nil {
return nil, err
}
require.NoError(b, err)
tagNames = append(tagNames, []byte("not_exist"))

var (
Expand All @@ -91,17 +86,15 @@ func prepareData(b *testing.B) ([]encodedTagsWithTagName, error) {
for i := 0; i < b.N; i++ {
tagName := tagNames[rnd.Intn(len(tagNames))]
encodedTags, err = base64.StdEncoding.DecodeString(samples[rnd.Intn(len(samples))])
if err != nil {
return nil, err
}
require.NoError(b, err)

result = append(result, encodedTagsWithTagName{
encodedTags: encodedTags,
tagName: tagName,
})
}

return result, nil
return result
}

func decodeTagNames(encodedTags []byte) ([][]byte, error) {
Expand Down

0 comments on commit 59887f4

Please sign in to comment.